Skip to main content

Sync channel status across devices

When the current user changes a channel's pin state or DND level on one device, the change is synchronized to their other devices in real time. Register an NCChannelHandler to receive these sync notifications.

Register the handler

swift
import NexconnChatSDK
final class MyChannelHandler: NSObject, ChannelHandler {}

let handler = MyChannelHandler()
NCEngine.addChannelHandler(identifier: "MY_CHANNEL_HANDLER", handler: handler)
// Remove when no longer needed
NCEngine.removeChannelHandler(forIdentifier: "MY_CHANNEL_HANDLER")

Implement NCChannelHandler

swift
import NexconnChatSDK
final class MyViewController: NSObject, ChannelHandler {
// Channel pin state changed on another device
func onChannelPinnedSync(_ event: ChannelPinnedSyncEvent) {
print("Channel \(event.channelIdentifier.channelId) pinned: \(event.isPinned)")
}

// Channel DND level changed on another device
func onChannelNoDisturbLevelSync(_ event: ChannelNoDisturbLevelSyncEvent) {
print("Channel \(event.channelIdentifier.channelId) DND level changed to: \(event.level.rawValue)")
}

// Remote channel list sync completed
func onRemoteChannelsSyncCompleted(_ event: RemoteChannelsSyncCompletedEvent) {
if event.error == nil {
print("Remote channels synced.")
}
}

// Channel status sync completed
func onChannelStatusSyncCompleted(_ event: ChannelStatusSyncCompletedEvent) {
if event.error == nil {
print("Channel status synced.")
}
}
}

Callback reference

CallbackTrigger
onChannelPinnedSync:Pin state changed on another device
onChannelNoDisturbLevelSync:DND level changed on another device
onRemoteChannelsSyncCompleted:Remote channel list sync completed
onChannelStatusSyncCompleted:Channel status sync completed