Skip to main content

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
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.")
}
}

Remove a channel from a tag

Call deleteTags(_:completion:) on the channel instance:

swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.deleteTags(["tagId"]) { error in
if error == nil {
print("Tag removed from channel.")
}
}

Or use deleteChannels(_:completion:) on the tag:

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 }

Get a channel's tags

Call getTags(completion:) on a channel instance:

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)")
}
}

Get channels in a tag (paginated)

Use NCTag.createTaggedChannelsQuery(params:):

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)")
}
}

Get the total unread count for a tag

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)")
}

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.