Channel overview
The Chat SDK uses channel objects to represent channels. All channel types (Direct, Group, Open, Community, System) inherit from NCBaseChannel.
Channel types
Nexconn supports multiple channel types for different use cases. The client SDK uses the NCChannelType enum:
| Enum value | Channel type |
|---|---|
| NCChannelTypeDirect | Direct channel |
| NCChannelTypeGroup | Group channel |
| NCChannelTypeCommunity | Community channel |
| NCChannelTypeOpen | Open channel |
| NCChannelTypeSystem | System channel |
Direct channel
A one-to-one channel between two users. The two users do not need to be friends — Nexconn does not manage user relationships. Messages are stored in the local database.
Group channel
A channel with two or more users. Channel member information is managed by your app. Nexconn delivers messages to all group members. Each group supports up to 3,000 members with no limit on the number of groups per app. Messages are stored in the local database.
Community channel
A multi-user chat with no member limit. Supports high-volume concurrent messaging and push notifications. Member information is managed by your app. Each user can join up to 100 community channels. Messages are stored in the local database. See Community channel overview.
Open channel
Supports unlimited participants with high-volume concurrent real-time messaging. Users stop receiving messages after leaving the open channel. No push notification support. The SDK does not save open channel messages — all data is cleared when the user leaves. See Open channel overview.
System channel
A channel where system accounts send messages to users. These channels can be created by broadcast messages or single notification messages (for example, friend request notifications).
Channel properties
The NCBaseChannel class provides the following key properties:
| Property | Type | Description |
|---|---|---|
| channelType | NCChannelType | Channel type: direct, group, open, system, or community |
| channelId | NSString | Channel ID. For direct channels, this is the other user's ID. For group/open/community channels, this is the corresponding channel ID. |
| unreadCount | NSInteger | Number of unread messages |
| mentionedMeCount | NSInteger | Number of unread messages that mention the current user |
| mentionedCount | NSInteger | Total number of mention messages |
| isPinned | BOOL | Whether the channel is pinned |
| noDisturbLevel | NCChannelNoDisturbLevel | Do not disturb level. See Do not disturb overview. |
| operationTime | long long | Operation timestamp in milliseconds. Updated by pinning and other operations. Used as cursor for paginated queries. |
| latestMessage | NCMessage | Last message stored locally. See Message types. |
| draft | NSString | Draft text saved in the channel. See Draft. |
| translateStrategy | NCTranslateStrategy | Text translation strategy for this channel |
latestMessage (NCMessage) key properties:
| Property | Type | Description |
|---|---|---|
| clientId | long long | Locally unique message ID |
| messageId | NSString | Server-assigned globally unique message ID (only available for successfully sent messages) |
| senderUserId | NSString | Sender's user ID |
| direction | NCMessageDirection | Message direction: send or receive |
| sentStatus | NCSentStatus | Message sending status |
| sentTime | long long | Send time (Unix timestamp in milliseconds) |
| messageType | NSString | Message type name |
| content | NCMessageContent | Message content body |
| metadata | NSDictionary | Message metadata |
| receivedStatusInfo | NCMessageReceivedStatusInfo | Message received status |
Basic channel operations
Create or get a channel instance
- Swift
- Objective-C
import NexconnChatSDK
// Direct channel
let directChannel = DirectChannel(channelId: "userId")
// Group channel
let groupChannel = GroupChannel(channelId: "groupId")
// Open channel
let openChannel = OpenChannel(channelId: "chatroomId")
// Direct channel
NCDirectChannel *directChannel = [[NCDirectChannel alloc] initWithChannelId:@"userId"];
// Group channel
NCGroupChannel *groupChannel = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
// Open channel
NCOpenChannel *openChannel = [[NCOpenChannel alloc] initWithChannelId:@"chatroomId"];
Each call to initWithChannelId: returns a new channel instance configured with the given ID.
Get a channel instance
- Swift
- Objective-C
import NexconnChatSDK
let identifier = ChannelIdentifier(channelType: .direct, channelId: "userId")
BaseChannel.getChannels(identifiers: [identifier]) { channels, error in
guard let channel = channels?.first else { return }
print("Channel loaded: \(channel.channelId)")
}
NCChannelIdentifier *identifier =
[[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect
channelId:@"userId"];
[NCBaseChannel getChannels:@[identifier]
completion:^(NSArray<NCBaseChannel *> * _Nullable channels, NCError * _Nullable error) {
NCBaseChannel *channel = channels.firstObject;
if (channel != nil) {
NSLog(@"Channel loaded: %@", channel.channelId);
}
}];
If you already know the channel type and ID, you can also create a typed instance with initWithChannelId: and then call reloadWithCompletion: to fetch the latest state.
Release a channel instance
The current iOS SDK does not expose a destroy API on NCBaseChannel. Channel instances are lightweight objects. Release your own references when you no longer need an instance.
Create a channel list query
- Swift
- Objective-C
import NexconnChatSDK
let params = ChannelsQueryParams()
params.setChannelTypes([.direct])
params.pageSize = 20
let query = BaseChannel.createChannelsQuery(params: params)
query.loadNextPage { page, error in
let channels = page?.data ?? []
print("Loaded \(channels.count) channels")
}
NCChannelsQueryParams *params = [[NCChannelsQueryParams alloc] init];
params.channelTypes = @[@(NCChannelTypeDirect)];
params.pageSize = 20;
NCChannelsQuery *query = [NCBaseChannel createChannelsQueryWithParams:params];
[query loadNextPageWithCompletion:^(NSArray *channels, NCError *error) {
if (!error) {
NSLog(@"Loaded %lu channels", (unsigned long)channels.count);
}
}];
Create a channel search query
- Swift
- Objective-C
import NexconnChatSDK
let query = ChannelSearchQuery()
query.keyword = "Project"
query.loadNextPage { page, error in
let channels = page?.data ?? []
// Handle results
}
NCChannelSearchQuery *query = [[NCChannelSearchQuery alloc] init];
query.keyword = @"Project";
[query loadNextPageWithCompletion:^(NSArray *channels, NCError *error) {
// Handle results
}];
Mark multiple channels as read
- Swift
- Objective-C
import NexconnChatSDK
for channel in channels {
channel.clearUnreadCount(completion: nil)
}
for (NCBaseChannel *channel in channels) {
[channel clearUnreadCountWithCompletion:nil];
}
Delete multiple channels
Use deleteChannels:completion: (see Delete a channel).
Clear unread count
Use clearUnreadCountWithCompletion: on a channel instance (see Handle unread count).