Question

So I have push notifications working perfectly except that the badge notification is only ever going up to 3 and then, even though it shows those notifications, the badge number doesn't go above that. Here is badge register and clear code on launch to clear the badge:

[[UIApplication sharedApplication] registerForRemoteNotificationTypes:
 (UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

I have no other code setting the badge.

I'll be happy to answer any question, but I need to get this fixed^^; Thanks in advance for any help!

Edits in italics.

Was it helpful?

Solution

If you intend to update the badge count as a result of arriving push notifications, you should probably set its value in the server (using the badge property of the push notification).

When your server sends push notifications to your app they are not guaranteed to arrive. If you send several notifications in a short time period, it's possible that Apple will deliver only some of them. Therefore it's not a good practice to increase the badge count in the app when a notification arrives.

Another reason why it's not a good practice is that if you update the badge programatically in the app, the update will take place only when the user taps the notification (and if the user opens the application via the launch icon, you wouldn't even know there was a notification, so you won't know to update the badge).

The idea of the badge is that the server sends it as part of the push notification. Then iOS displays the badge on the app icon even if you don't tap the notification. This tells the user he/she has new information to view in the app. When the app is launched, you should display the new data and clear the badge (by setting its value to 0).

Usually the badge number returned by the server contains the number of new data items available at the server for the user of the app (such as the number of unread emails). Letting the server maintain this number makes even more sense when the user can access the data from the server via multiple devices. If you read all your new emails on your laptop, you don't want your email app to show a badge number that indicates unread messages.

OTHER TIPS

Be aware that setApplicationIconBadgeNumber is not cumulative. It will not do the arithmetic for you. You need to set the badge number to the exact value you want. So if you wish to tally up the notifications, you will need to check the current value of applicationIconBadgeNumber and then add 1 to it for each notification.

Sending 0 means "no change" when in the context of a UILocalNotification and means "hide" when in the context of UIApplication.

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