Will IOS increment a push notfication badge number?

11,137

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]
}
Share:
11,137
Dickens A S
Author by

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, 2022

Comments

  • Dickens A S
    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
    Dickens A S almost 9 years
    If 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
    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
    GvSharma almost 6 years
    How 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?