Browse SDKs · iOS
Platform
SDKsiOS

Set the app badge count

Synchronize the app's current unread count with the OpenIMClientSDK push badge state.

Copy

Invoke setAppBadge:onSuccess:onFailure: to report the application's overall unread message count to the SDK, synchronizing badge numbers with the server and push notification services:

Parameters

ParameterTypeRequiredDescription
countNSIntegerYesThe aggregate total unread message count across the entire application (non-negative integer). Pass the global unread count rather than a single conversation's count.

Code example

[[OIMManager manager] setAppBadge:totalUnreadCount
                        onSuccess:^(NSString * _Nullable data) {
                            NSLog(@"setAppBadge success");
                        }
                        onFailure:^(NSInteger code, NSString * _Nullable msg) {
                            NSLog(@"setAppBadge failed: %ld %@", (long)code, msg);
                        }];

Return value

The onSuccess callback returns confirmation when the SDK successfully records the badge count.

State changes after the call

  1. Push service synchronization: This call updates badge metadata for backend push delivery; it does not alter conversation-level unread records. To update the app icon badge on the iOS home screen, pair this call with Apple's user notification framework.
  2. Re-query calibration: For unread counter calculation and listener maintenance, refer to Retrieve and maintain the total unread count.