Badge Notifications

Read the Pulsate unread count, keep your app-icon badge in sync, and clear notifications with the iOS SDK.

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.

Reading the unread count

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)"
    }
}

Observing badge changes with a delegate

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
    }
}

Clearing notifications

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

PULPulsateFactory.getDefaultInstance()?.clearAllNotifications()

📘

Note

The SDK keeps the system app-icon badge in sync for you. Prefer the SDK's getFeedUnreadCount(completion:) or PULPulsateBadgeDelegate over reading UIApplication.shared.applicationIconBadgeNumber directly — the latter is deprecated on iOS 17+ in favor of UNUserNotificationCenter.current().setBadgeCount(_:), and it reflects the raw system badge rather than the Pulsate unread count.