Set and use channel tags
Organize channels into groups using tags. Each user can create up to 20 tags, and each tag can contain up to 1,000 channels.
tip
Before tagging a channel, create the tag first. See Manage Channel Tag Data.
Add a channel to a tag
Call addChannels(_:completion:) on an NCTag instance:
- Swift
- Objective-C
swift
import NexconnChatSDK
let identifier = ChannelIdentifier(channelType: .direct, channelId: "targetUserId")
let tag: Tag? = nil // Replace with a Tag instance from Tag.createTag/getTags
guard let tag else { return }
tag.addChannels(identifiers: [identifier]) { error in
if error == nil {
print("Channel added to tag.")
}
}
Objective C
NCChannelIdentifier *identifier =
[[NCChannelIdentifier alloc] initWithChannelType:NCChannelTypeDirect
channelId:@"targetUserId"];
NCTag *tag; // Obtained from NCTag.createTag or NCTag.getTags
[tag addChannels:@[identifier] completion:^(NCError *error) {
if (error == nil) {
NSLog(@"Channel added to tag.");
}
}];
Remove a channel from a tag
Call deleteTags(_:completion:) on the channel instance:
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.deleteTags(["tagId"]) { error in
if error == nil {
print("Tag removed from channel.")
}
}
Objective C
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
[channel deleteTags:@[@"tagId"]
completion:^(NCError *error) {
if (error == nil) {
NSLog(@"Tag removed from channel.");
}
}];
Or use deleteChannels(_:completion:) on the tag:
- Swift
- Objective-C
swift
import NexconnChatSDK
let tag: Tag? = nil // Replace with a Tag instance from Tag.createTag/getTags
guard let tag else { return }
let identifier = ChannelIdentifier(channelType: .direct, channelId: "targetUserId")
tag.deleteChannels(identifiers: [identifier]) { error in }
Objective C
[tag deleteChannels:@[identifier] completion:^(NCError *error) {}];
Get a channel's tags
Call getTags(completion:) on a channel instance:
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.getTags { tags, error in
for tagInfo in tags ?? [] {
print("Tag: \(tagInfo.tag.tagId) (\(tagInfo.tag.tagName)), pinned: \(tagInfo.isPinned)")
}
}
Objective C
[channel getTagsWithCompletion:^(NSArray<NCChannelTagInfo *> *tags, NCError *error) {
for (NCChannelTagInfo *tagInfo in tags) {
NSLog(@"Tag: %@ (%@), pinned: %d", tagInfo.tag.tagId, tagInfo.tag.tagName, tagInfo.isPinned);
}
}];
Get channels in a tag (paginated)
Use NCTag.createTaggedChannelsQuery(params:):
- Swift
- Objective-C
swift
import NexconnChatSDK
let params = TaggedChannelsQueryParams()
params.tagId = "myTagId"
params.pageSize = 20
params.startTime = 0 // Start from most recent
let query = Tag.createTaggedChannelsQuery(params: params)
query.loadNextPage { page, error in
for channel in page?.data ?? [] {
print("Channel: \(channel.channelId)")
}
}
Objective C
NCTaggedChannelsQueryParams *params = [[NCTaggedChannelsQueryParams alloc] init];
params.tagId = @"myTagId";
params.pageSize = 20;
params.startTime = 0; // Start from most recent
NCTaggedChannelsQuery *query = [NCTag createTaggedChannelsQueryWithParams:params];
[query loadNextPageWithCompletion:^(NSArray<NCBaseChannel *> *channels, NCError *error) {
for (NCBaseChannel *channel in channels) {
NSLog(@"Channel: %@", channel.channelId);
}
}];
Get the total unread count for a tag
- Swift
- Objective-C
swift
import NexconnChatSDK
let tag: Tag? = nil // Replace with a Tag instance from Tag.createTag/getTags
guard let tag else { return }
tag.getUnreadCount(containNoDisturb: false) { count, error in
print("Unread in tag: \(count)")
}
Objective C
[tag getUnreadCountWithContainNoDisturb:NO
completion:^(NSInteger count, NCError * _Nullable error) {
NSLog(@"Unread in tag: %ld", (long)count);
}];
Pin a channel within a tag
info
The current public NCTag API does not expose pin/unpin operations for a channel inside a tag. Use the public tag APIs for channel assignment, tagged-channel queries, and unread-count management.