Join an open channel
To join an open channel, create an NCOpenChannel instance with the channel ID, then call enterChannel(params:completion:).
- The SDK automatically rejoins open channels after a network reconnection if the user has not explicitly exited.
- Create the open channel via the Server API, then distribute the channel ID to clients to join.
Limitations
- By default, a user can only be in one open channel at a time. Joining a new channel automatically exits the previous one. Enable Allow single user to join multiple open channels in the Console to change this behavior.
- On join, the SDK retrieves up to 50 recent messages. The iOS SDK default is
20. Configure Join open channel message type filtering in the Console to limit which message types are retrieved.
Join an existing open channel
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = OpenChannel(channelId: "channelId") else {
return
}
let params = EnterOpenChannelParams()
params.messageCount = 20
params.extra = nil
channel.enterChannel(params: params) { response, error in
if let error {
print("Failed to join: \(error.localizedDescription)")
return
}
guard let response else { return }
print("Joined. Members: \(response.memberCount)")
print("Channel created at: \(response.createTime)")
print("All muted: \(response.isAllChannelMuted)")
print("Current user muted: \(response.isCurrentUserMuted)")
}
Objective C
NCOpenChannel *channel = [[NCOpenChannel alloc] initWithChannelId:@"channelId"];
NCEnterOpenChannelParams *params = [[NCEnterOpenChannelParams alloc] init];
params.messageCount = 20; // Number of recent messages to pull on enter (-1 to 50)
params.extra = nil; // Optional extra info
[channel enterChannelWithParams:params completion:^(NCOpenChannelEnterResponseInfo *response, NCError *error) {
if (error == nil) {
NSLog(@"Joined. Members: %ld", (long)response.memberCount);
NSLog(@"Channel created at: %lld", response.createTime);
NSLog(@"All muted: %d", response.isAllChannelMuted);
NSLog(@"Current user muted: %d", response.isCurrentUserMuted);
} else {
NSLog(@"Failed to join: %@", error);
}
}];
NCEnterOpenChannelParams
| Parameter | Type | Default | Description |
|---|---|---|---|
messageCount | NSInteger | 20 | Number of recent messages to retrieve on enter. Value rules: -1 = retrieve no history, 0 = use SDK default (20), 1...50 = retrieve that number of recent messages. |
extra | NSString | nil | Optional extra information. |
NCOpenChannelEnterResponseInfo
| Property | Type | Description |
|---|---|---|
createTime | int64 | Channel creation time (millisecond timestamp) |
memberCount | NSInteger | Current member count |
isAllChannelMuted | BOOL | Whether the channel is globally muted |
isCurrentUserMuted | BOOL | Whether the current user is globally muted |
isCurrentChannelMuted | BOOL | Whether the current user is muted in this channel |
isCurrentChannelInAllowlist | BOOL | Whether the current user is on the channel's mute allowlist |
enterTime | int64 | Channel join time (millisecond timestamp) |
Auto-rejoin after reconnection
The SDK automatically rejoins open channels after a network reconnection. No action is required. After rejoining, the SDK retrieves the same number of messages as in the original join call.
tip
Messages retrieved after reconnection may already exist locally. Deduplicate before displaying.