Apple push notification icon number

I developed a server-side application to maintain the icon number as an increment or decrement after receiving a new notification and deleting after viewing the notification, which works fine.

But there are some problems when displaying the icon, the actual scenario - after receiving a new notification on the device, I press the cancel button, then the icon number is displayed correctly, after which I will open the application and close the delete application icon. This means that I am not sending a request to the server, that the notification was viewed by me, and now you can reduce the icon by one. Then, the icon is also removed from the application icon.

My question is that when we open the application, the icon number is automatically deleted from the (application) of the device? or will it show until it is set to zero?

+7
source share
2 answers

It will show until you set it to zero, and you can do it with the following code:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0] 


EDIT:
Most often, set the icon number when receiving a notification in the application:didReceiveRemoteNotification: or application:didFinishLaunchingWithOptions: your UIApplicationDelegate class.

See the programming guide for local and push notifications for more information.

+12
source

If you want to change the icon of the icon, use the following code.

  - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { application.applicationIconBadgeNumber = 0; NSLog(@"userInfo %@",userInfo); for (id key in userInfo) { NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]); } [application setApplicationIconBadgeNumber:[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue]]; NSLog(@"Badge %d",[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue]); } 

We also need to modify the php file. So we can automatically change the icon icon

 // Create the payload body $body['aps'] = array( 'alert' => $message, 'sound' => 'default', 'id' => '135', 'badge' => 8 ); 
0
source

All Articles