Ios - local notification that does not update the icon number when closing the application

I noticed that when a local notification is received on the ios device, the notification appears in the Notification Center, but the application icon number does not update when the application is closed.

I need to touch the notification in the Notification Center that a local push message will be transferred to the application.

Is this normal behavior? Can this be solved using remote push notifications?

+6
source share
2 answers

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"; //the following line is important to set badge number localNotification.applicationIconBadgeNumber++; [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

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]]; //... } 
+13
source

iPhone: Add app icon through local notification

It is not possible to dynamically update the icon number with local notifications while your application is in the background. therefore you should use push notifications. You can enlarge the icon only when you launch the application in the foreground and look for an alternative solution that you can go with here.

iPhone: Add app icon through local notification

0
source

All Articles