Push notification badge reset count

13,139

Solution 1

To clear the badge count whenever the application becomes active, simply include your line of code:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

In the AppDelegate.m file's applicationDidBecomeActive delegate method.

applicationDidFinishLaunchingWithOptions is only called on the initial launch, and does not get called again when the application goes to the background and back to the foreground.

Solution 2

For Swift 3.0

//AppleDelgate.swift
 func applicationDidBecomeActive(_ application: UIApplication) {
        //....
        application.applicationIconBadgeNumber = 0
       //....
}
Share:
13,139
Automator21
Author by

Automator21

Updated on June 07, 2022

Comments

  • Automator21
    Automator21 about 2 years

    I'm using PushBot as my push notification service, my issue is how do I reset the badge count. I've search and read to use this line of code:

    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    

    The only way the badge count gets reset is if I quit the app from running on the mulit-task bar and launch the app again, any help is greatly appreciated. Thanks,

  • Brad Adams
    Brad Adams almost 8 years
    This appears to be working, but the next time I receive a a notification, the count isn't 1. It's the count that was removed + 1 (the total notification count since the app was installed). Any ideas?
  • Terence
    Terence over 7 years
    I'm also getting "count that was removed" + 1. Any help? I've put that code in applicationDidBecomeActive AND applicationDidFinishLaunchingWithOptions
  • Marcus Adams
    Marcus Adams over 7 years
    Are you talking about the badge number in a remote notification? That's up to you to set on the server when you send the remote notification.