Skip to content

Badge Number Delegate

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

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

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(_:)