iOS Conversation: Unread Count
Retrieve totals and updates of unread messages in iOS
Total unread messages
To get the user's total unread message count, the following makes an API call to sync messages with server to get the latest count.
BrandMessengerManager.getTotalUnreadCount { count, error in
}
[BrandMessengerManager getTotalUnreadCountWithComplete:^(NSUInteger count, NSError * _Nullable error) {
}];
Real-time update of count
To update the unread message count in real-time for any incoming messages, see this example notification with the name: BRAND_MESSENGER_UNREAD_COUNT
NotificationCenter.default.addObserver(self, selector: #selector(onUnreadCount(obj:)), name: NSNotification.Name("BRAND_MESSENGER_UNREAD_COUNT"), object: nil)
To remove the observer of new notifications, you can add the following in -(void)viewWillDisappear
:
NotificationCenter.default.removeObserver(self, name: NSNotification.Name("BRAND_MESSENGER_UNREAD_COUNT"), object: nil)
Show badge count
To show the badge count on the Application icon, set the UnreadCountType
to 1
.
[KBMUserDefaultsHandler setUnreadCountType:1];
KBMUserDefaultsHandler.setUnreadCountType(1)
Updated 9 months ago