Skip to content

Badge Notifications

The Pulsate SDK tracks the number of unread items in a user’s Feed (campaigns and messages) and keeps the app-icon badge synchronized automatically. You can also read the current count yourself to surface it elsewhere in your UI, and clear all notifications when appropriate.

To fetch the current unread Feed count on demand, use getFeedUnreadCount(completion:):

import PULPulsate
guard let manager = PULPulsateFactory.getDefaultInstance() else { return }
manager.getFeedUnreadCount { unreadCount in
// Update your UI on the main thread
DispatchQueue.main.async {
self.badgeLabel.text = "\(unreadCount)"
}
}

To be notified whenever the badge value changes, assign a badgeDelegate and implement PULPulsateBadgeDelegate. After assigning the delegate, call getBadgeCount() to request the current value — the result is delivered to badgeUpdated(_:).

import PULPulsate
final class FeedBadgeObserver: NSObject, PULPulsateBadgeDelegate {
func start() {
guard let manager = PULPulsateFactory.getDefaultInstance() else { return }
manager.badgeDelegate = self
manager.getBadgeCount()
}
func badgeUpdated(_ badgeNumber: Int) {
// Fired with the latest total unread count
}
func badgeIncrement(by badgeIncrement: Int, totalCount badgeNumber: Int) {
// Fired when the count goes up
}
func badgeDecrement(by badgeDecrement: Int, totalCount badgeNumber: Int) {
// Fired when the count goes down
}
}

To reset the app-icon badge to zero and clear delivered and pending notifications, call:

PULPulsateFactory.getDefaultInstance()?.clearAllNotifications()