Will IOS increment a push notfication badge number?
Solution 1
iOS
doesn't sum the badge numbers you send to the app. It just displays the latest badge number sent from your server. You server should send a push notification with badge number of 10 if that's the badge number you want to display.
Solution 2
The server who sent the notification has to set the number to 10, not you. See here for more information: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/APNSOverview.html#//apple_ref/doc/uid/TP40008194-CH8-SW1
Solution 3
You can control badge number with aps
dictionary attached to push notification.
There is a badge
key you can use to set proper count - but counting amount of push notification has to be done on server side - iOS doesn't do that automatically.
Checkout the APS reference table 9-1 here
To reset badge count you should use UIApplication method.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
Depending on the application logic you need to place that in different locations, but most common usage is to do that on application becoming active.
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
}
![Dickens A S](https://i.stack.imgur.com/k8AP8.png?s=256&g=1)
Dickens A S
I am an Electronic hobbyist since 1992 (my school days). Started programming by 1998. Since then I dwell as a software programming hobbyist and freelancer.
Updated on June 05, 2022Comments
-
Dickens A S about 2 years
I need to write a application which can show badge number on the icon.
I am able to receive the push notification and the badge number is also getting displayed as 5.
But, when the second push notification received while the app is still not yet launched the badge still displays 5.
It is not supposed to be 10?
-
Dickens A S almost 9 yearsIf there is an SMS application and 2 SMS is read and 3 SMS newly arrived will it not display the correct value, how it works there?
-
Eran almost 9 years@Dickens SMS is a different mechanism and unrelated to push notifications. The server should know how many unread messages each instance of the app has (the app should notify the server regarding how many messages are read/unread when it is launched. It can reset the badge count to 0 when all the messages are read).
-
GvSharma almost 6 yearsHow can i update server when it is offline whether the message has been seen or not by the user?Later how can i get updated badge count?