Pin a channel
Pin a channel to keep it at the top of the channel list. The pin state is synced to the Nexconn server and synchronized across devices.
Pin a channel
Call pinWithParams:completion: on a channel instance:
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
let params = PinParams(updateOperationTime: false)
channel.pin(params: params) { error in
if error == nil {
print("Channel pinned.")
}
}
Objective C
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
NCPinParams *params = [[NCPinParams alloc] initWithUpdateOperationTime:NO];
[channel pinWithParams:params
completion:^(NCError * _Nullable error) {
if (error == nil) {
NSLog(@"Channel pinned.");
}
}];
Unpin a channel
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.unpin { error in
if error == nil {
print("Channel unpinned.")
}
}
Objective C
[channel unpinWithCompletion:^(NCError *error) {
if (error == nil) {
NSLog(@"Channel unpinned.");
}
}];
Listen for pin status changes across devices
Register an NCChannelHandler to receive pin status changes in real time when they are modified on another device:
- Swift
- Objective-C
swift
import NexconnChatSDK
final class MyChannelHandler: NSObject, ChannelHandler {
func onChannelPinnedSync(_ event: ChannelPinnedSyncEvent) {
print("Channel \(event.channelIdentifier.channelId) pinned: \(event.isPinned)")
}
}
let handler = MyChannelHandler()
NCEngine.addChannelHandler(identifier: "MY_CHANNEL_HANDLER", handler: handler)
Objective C
[NCEngine addChannelHandlerWithIdentifier:@"MY_CHANNEL_HANDLER" handler:self];
// NCChannelHandler callback
- (void)onChannelPinnedSync:(NCChannelPinnedSyncEvent *)event {
NSLog(@"Channel %@ pinned: %d", event.channelIdentifier.channelId, event.isPinned);
}
See Sync Channel Status Across Devices for full details.