Browse SDKs · iOS
SDKsiOS

Retrieve and maintain the total unread count

Retrieve and continuously maintain the account’s total unread count with OpenIM iOS SDK.

Copy

This query returns a snapshot of the total unread count across all conversations for the current account. Do not derive it by summing unreadCount values from the currently loaded pages.

[[OIMManager manager] getTotalUnreadMsgCountWithOnSuccess:^(NSInteger count) {
    [badgeStore setTotalUnread:count];
} onFailure:nil];

The query itself does not trigger a delegate. This page is the sole owner of subsequent total-count updates:

@interface TotalUnreadSync : NSObject <OIMConversationListener>
@end

@implementation TotalUnreadSync
- (void)onTotalUnreadMessageCountChanged:(NSInteger)count {
    [badgeStore setTotalUnread:count];
}
@end

[[OIMManager callbacker] addConversationListener:totalUnreadSync];
// When the account scope ends:
[[OIMManager callbacker] removeConversationListener:totalUnreadSync];