Sync read status across devices
In a multi-device scenario, read and unread status is stored locally on each device. When a user reads messages on one device, you can sync that state to the user's other devices by clearing the unread count.
tip
Clearing the unread count on the current device sends a sync notification to other devices logged in with the same account.
Clear unread count (syncs to other devices)
Call clearUnreadCount(completion:) on a channel instance. This resets the local unread counter and notifies the user's other devices of the read state:
- Swift
- Objective-C
swift
import NexconnChatSDK
guard let channel = DirectChannel(channelId: "targetUserId") else { return }
channel.clearUnreadCount { isCleared, error in
if isCleared {
print("Read status cleared and synced.")
}
}
Objective C
NCDirectChannel *channel = [[NCDirectChannel alloc] initWithChannelId:@"targetUserId"];
[channel clearUnreadCountWithCompletion:^(BOOL isCleared, NCError *error) {
if (isCleared) {
NSLog(@"Read status cleared and synced.");
}
}];
- Swift
- Objective-C
swift
import NexconnChatSDK
// Group channel example
guard let group = GroupChannel(channelId: "groupId") else { return }
group.clearUnreadCount { isCleared, error in
if isCleared {
print("Group unread count cleared.")
}
}
Objective C
// Group channel example
NCGroupChannel *group = [[NCGroupChannel alloc] initWithChannelId:@"groupId"];
[group clearUnreadCountWithCompletion:^(BOOL isCleared, NCError *error) {
if (isCleared) {
NSLog(@"Group unread count cleared.");
}
}];