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 channel 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"];
Returns nil if channelId is empty.
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, .group])
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), @(NCChannelTypeGroup)];
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.limit = 20
query.loadNextPage { page, error in
let channels = page?.data ?? []
// Handle results
}
NCChannelSearchQuery *query = [[NCChannelSearchQuery alloc] init];
query.keyword = @"Project";
query.limit = 20;
[query loadNextPageWithCompletion:^(NSArray *channels, NCError *error) {
// Handle results
}];
Delete channels
- Swift
- Objective-C
import NexconnChatSDK
let id1 = ChannelIdentifier(channelType: .direct, channelId: "userId")
let id2 = ChannelIdentifier(channelType: .group, channelId: "groupId")
BaseChannel.deleteChannels(identifiers: [id1, id2]) { error in
if error == nil {
print("Channels deleted")
}
}
NCChannelIdentifier *id1 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect channelId:@"userId"];
NCChannelIdentifier *id2 = [[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeGroup channelId:@"groupId"];
[NCBaseChannel deleteChannels:@[id1, id2] completion:^(NCError *error) {
if (!error) {
NSLog(@"Channels deleted");
}
}];
Clear unread count
- Swift
- Objective-C
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.clearUnreadCount { isCleared, error in
if isCleared {
print("Unread count cleared")
}
}
[channel clearUnreadCountWithCompletion:^(BOOL success) {
if (success) {
NSLog(@"Unread count cleared");
}
}];