Overview
The badge count feature displays the total number of unread messages for a user as a badge on the app icon. When enabled, each push notification includes anunreadMessageCount field that your app can use to update the badge.
This is a premium feature. To enable badge count for your application, please contact the CometChat team.
How it works
- When a new message is sent, the unread count is incremented for all receivers.
- When a user reads a message (read receipt), the count is decremented.
- The count is included in the push notification payload as
unreadMessageCount. - Your app uses this value to set the badge on the app icon.
Payload structure
When badge count is enabled, the push notification payload includes theunreadMessageCount field:
FCM (Android)
Best practices
-
Always handle missing values - The
unreadMessageCountfield may be undefined if the feature is not enabled. - Clear badge on app open - Reset the badge when users open the app to avoid stale counts.
- Sync with read receipts - The badge count automatically decrements when read receipts are sent, so ensure your app sends read receipts properly.
- Test across platforms - Badge behavior varies between iOS and Android; test thoroughly on both.
Troubleshooting
| Issue | Solution |
|---|---|
| Badge count not appearing | Ensure the feature is enabled for your app. Contact CometChat team to enable it. |
| Count not updating | Ensure read receipts are being sent when messages are read |
| Badge shows wrong number | Clear the badge on app open and let it sync from the next notification |