On this page

Join channels

Requires App Context

Enable App Context on your keyset in the Admin Portal to manage memberships.

Creates a channel membership for the current user. The user is recorded as a channel member.

Listening for messages

join() no longer returns a message stream or accepts a message callback. To receive messages after joining, call onMessageReceived() or use channel.stream.messages() separately.

Method signature

join() performs these actions:

  • Subscribes the user to a channel
  • Creates a MembershipImpl object for the user-channel relationship

This method takes the following parameters:

1channel.join(
2 custom: [String: JSONCodableScalar]? = nil,
3 status: String? = nil,
4 type: String? = nil
5) async throws -> MembershipImpl

Input

* required
ParameterDescription
custom
Type: [String: JSONCodableScalar]
Default:
nil
Any custom properties or metadata associated with the channel-user membership in the form of a JSON. Values must be scalar only; arrays or objects are not supported. App Context filtering language doesn’t support filtering by custom properties.
status
Type: String
Default:
nil
Tag that categorizes the membership by its state, like active or inactive.
type
Type: String
Default:
nil
Tag that categorizes the membership by its function, like moderator or viewer.

Output

ParameterDescription
MembershipImpl
Type: MembershipImpl
Returned object containing info on the newly created user-channel membership.

Sample code

Sample code

The code samples in Swift Chat SDK focus on asynchronous code execution.

You can also write synchronous code as the parameters are shared between the async and sync methods but we don't provide usage examples of such.

Access membership properties

join() returns a MembershipImpl object directly. Access membership properties such as channel.id directly on the returned value, for example, joinResult.channel.id.

Join the support channel and mark this membership as premium to add information about your support plan.

1