Pulsate allows you to get callbacks every time a badge number update happens. All you need to do is implement the PULPulsateBadgeDelegate.
Example Usage with Objective-C:
In your AppDelegate.h add the following code
@interface AppDelegate : UIResponder <UIApplicationDelegate, PULPulsateBadgeDelegate>
In your AppDelegate.m
- (void)badgeUpdated:(NSInteger)badgeNumber {
}
-(void) badgeDecrementBy:(NSInteger)badgeDecrement totalCount:(NSInteger)badgeNumber {
}
-(void) badgeIncrementBy:(NSInteger)badgeIncrement totalCount:(NSInteger)badgeNumber {
}
Also in your AppDelegate in the didFinishLaunchingWithOptions method add the following code
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
PULPulsateManager* manager = [PULPulsateFactory getDefaultInstance];
manager.badgeDelegate = self;
return YES;
}
Example usage in Swift:
In your AppDelegate.swift
import UIKit
import CoreData
import PULPulsate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PULPulsateBadgeDelegate {
var window: UIWindow?
func badgeUpdated(_ badgeNumber: Int) {
}
func badgeDecrement(by badgeDecrement: Int, totalCount badgeNumber: Int) {
}
func badgeIncrement(by badgeIncrement: Int, totalCount badgeNumber: Int) {
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
do {
let authData: PULAuthorizationData = try PULAuthorizationData(appId: "APP_ID", andAppKey: "APP_KEY")
let pulsateManager = try PULPulsateFactory.getInstanceWith(authData, withLocationEnabled: true, withPushEnabled: true, withLaunchOptions: launchOptions)
pulsateManager.badgeDelegate = self;
} catch {
print(error)
}
return true
}
}
To get an updated badge from Pulsate you can use the "getBadgeCount" method. This method will send a request to Pulsate servers to get the current badge count. The badge count will be returned in the PULPulsateBadgeDelegate badgeUpdated callback.