Receive a callback every time Pulsate updates the app badge count by implementing PULPulsateBadgeDelegate.
Pulsate notifies you whenever the app badge count changes so you can track it or apply your own badge logic. Implement the PULPulsateBadgeDelegate protocol and assign it to the manager's badgeDelegate property.
The protocol delivers three callbacks:
| Method | Called when |
|---|---|
badgeUpdated(_:) | The badge is set to an absolute value |
badgeIncrement(by:totalCount:) | The badge is increased |
badgeDecrement(by:totalCount:) | The badge is decreased |
Implementation
Adopt PULPulsateBadgeDelegate and set badgeDelegate after creating the manager:
import UIKit
import PULPulsate
@main
class AppDelegate: UIResponder, UIApplicationDelegate, PULPulsateBadgeDelegate {
var window: UIWindow?
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
do {
let authData = try PULAuthorizationData(withAppId: "APP_ID", andAppKey: "APP_KEY")
let pulsateManager = try PULPulsateFactory.getInstance(
withAuthorizationData: authData,
withLaunchOptions: launchOptions
)
pulsateManager.badgeDelegate = self
} catch {
print("Pulsate init failed: \(error)")
}
return true
}
// MARK: - PULPulsateBadgeDelegate
func badgeUpdated(_ badgeNumber: Int) { }
func badgeIncrement(by badgeIncrement: Int, totalCount badgeNumber: Int) { }
func badgeDecrement(by badgeDecrement: Int, totalCount badgeNumber: Int) { }
}
Note
If you create the manager elsewhere, you can assign the delegate later using
PULPulsateFactory.getDefaultInstance()?.badgeDelegate = self.
Retrieving the badge count
getBadgeCount() sends a request to the server to fetch the current Pulsate badge count. The result is delivered asynchronously through the badgeUpdated(_:) callback — the method itself returns nothing.
PULPulsateFactory.getDefaultInstance()?.getBadgeCount()
// The value arrives in badgeUpdated(_:)
Tip
To read the unread feed count directly via a completion handler instead of the delegate, use
getFeedUnreadCount(completion:)on the manager.

