Unread Messages
Tracking unread messages in your app enhances user engagement by providing timely notifications.
How it works
- When a user receives a new message, the SDK triggers an event with the updated unread message count.
- You can listen for these events using an event observer. SeeEvents.
- You can also query the SDK at any time to retrieve the current unread message count at any time.
Get unread message count
Retrieve the total number of unread messages:
Swift
Zendesk.instance?.messaging?.getUnreadMessageCount()
Objective-C
Zendesk *instance = [Zendesk instance];
NSInteger unreadCount = [instance.messaging getUnreadMessageCount];
Retrieve the unread message count for a specific conversation:
Swift
Zendesk.instance?.messaging?.getUnreadMessageCount(conversationId)
Objective-C
Zendesk *instance = [Zendesk instance];
NSInteger unreadCount = [instance.messaging getUnreadMessageCountWithConversationId:conversationId];
Listen for unread message changes
To respond to changes in unread messages (for example, update a badge or send a notification), add an event observer to your Zendesk SDK instance. See Events for setup instructions and code samples.
For a working example, see the Unread Message Demo App.