iPhone: How to set the application badge, when the app is closed/in background?

11,478

Solution 1

From within your application you can use the applicationIconBadgeNumber property of UIApplication to set the badge number:

[UIApplication sharedApplication].applicationIconBadgeNumber = 1;

If you want to change the badge without the user launching your app, you need to use the push notification service. The Push Notification Service Programming Guide should have all the info you need.

Solution 2

It is possible via push notifications (as you've tagged) but bare in mind that if the user has disallowed push notifications it won't work.

To update the badge number via push, you need to include the following in your payload:

"badge" : 23

For more info about the payload, see this apple doc.

Share:
11,478
Stefan
Author by

Stefan

Updated on June 05, 2022

Comments

  • Stefan
    Stefan almost 2 years

    is it possible to set the application badge, while the app is in background mode or even closed? I haven't found anything, yet.

    Application Badge

  • 5hrp
    5hrp almost 13 years
    add to your answer (if you think it proper addon), that @Stefan also can use Local Notifications
  • Stefan
    Stefan almost 13 years
    Ok, that is what I hoped :-) At least there is a way to set the badge without having the app running.