You can use the applicationIconBadgeNumber parameter in a UILocalNotification object.
Mostly:
localNotificationObject.applicationIconBadgeNumber++;
Example:
UILocalNotification *localNotification = [[UILocalNotification alloc] init]; localNotification.fireDate = [[NSDate date] dateByAddingTimeInterval:20]; localNotification.alertBody = @"Some Alert";
But the problem is that the icon number does not increase by subsequent (several) local notifications (here is the script, but for simplicity, just say that the icon remains 1 even after 2 or more, local notifications back to the back).
In this case, Yes ... Push Notification seems to be a way (but keep in mind that Push Notifications are not always reliable ... check: link )
Well ... in order to use push notifications to properly update icon numbers, you need to know that you can send an icon counter in the push notification payload.
When this push notification is received, the number of icons is changed by iOS to the icon account specified in Push Notification (the application should not be open for this).
Example (continued):
Set applicationIconBadgeNumber to 0 as it helps in certain scenarios (optional)
- (void)applicationWillResignActive:(UIApplication *)application { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; } - (void)applicationWillTerminate:(UIApplication *)application { [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; }
Additionally:
You can also manually set the icon number when you close or close the application.
Usually ... in any or all of the following methods:
-applicationWillResignActive-applicationDidEnterBackground-applicationWillTerminate (set badgeNumber when the application closes)
Example:
- (void)applicationWillResignActive:(UIApplication *)application { //Called when the application is about to move from active to inactive state. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[[[UIApplication sharedApplication] scheduledLocalNotifications] count]]; //... } - (void)applicationWillTerminate:(UIApplication *)application { // Called when the application is about to terminate. [[UIApplication sharedApplication] setApplicationIconBadgeNumber:[[[UIApplication sharedApplication] scheduledLocalNotifications] count]]; //... }
source share