Question

I am getting the Push Notification from the Server. The server always sends badge=1 in payload.

The server side developer doesn't know anything about it. Can anybody tell me how can the server side developer handle badge count values so that iOS app will get the updated badge count (auto incremented badge count)?

  1. Can I auto increment it on iOS app side? If so, how?

  2. If no then how can the server developer handle badge count on server ? I saw several links which tell me that the server side should handle badge count.

Any sample or reference would be helpful.

Was it helpful?

Solution 2

The badge count is one of the parameters that can be sent in an Apple Push Notification payload from the server. The badge count usually reflects an amount of some kind of new data (such as unread emails) that the server knows about and wants to alert the app user about it. Therefore it should be done in the server side. The code that currently always sends 1 in the badge count should be changed to select the correct count.

You can do it in the client (increment it by one whenever a push notification arrives), but that won't be a good idea, because push notifications are not guaranteed to arrive. In addition, it will only be possible if the notification contains an alert in addition to the badge number, and the user taps on the notification to open the app (otherwise, your app wouldn't get the notification data if it's not already running).

OTHER TIPS

I think you can't do it iOS app side. It must come from the server.

What I do:

  • the server store an app badge number in the db for each user.
  • when the server send a notification, it increase that number by 1.
  • you also need to create a web service to reset the badge number which you will call when you launch the application.

You can change the badge number in the app with that line (e.g. in applicationDidBecomeActive):

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    application.applicationIconBadgeNumber = 0;
}

Hope this help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top