Search code examples
iphonecocoa-touchios4push-notificationuilocalnotification

iPhone: Incrementing the application badge through a local notification


is it possible to increment the application badge through a local notification while the app is not running?

I know how to set the badge, but haven't found any way to increment this value.

localNotification.applicationIconBadgeNumber = 23;

Update: I found a (far from being perfect) solution. You can predict what will happen, if the user doesn't open the app and add notifications for every +1 event.

An example:

  • For day 1: Count = 0
  • For day 2: localNotification.applicationIconBadgeNumber = 1;
  • For day 3: localNotification.applicationIconBadgeNumber = 2;
  • For day 4: localNotification.applicationIconBadgeNumber = 3;

==> Put these notifications in an array and set them before the application exits.

However, I'm searching for a better solution than this workaround.


Solution

  • The only way you're going to be able to dynamically set the badge number when your application isn't running is with push notifications. You'll have to track the updates on the server side.