9

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,

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
Automator21
  • 647
  • 2
  • 7
  • 11

3 Answers3

17

Just make a button on your UI and on his action put the code line:

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

It will reset it.

Take a look Here for some other implementations.

Community
  • 1
  • 1
15

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.

Marcus Adams
  • 53,009
  • 9
  • 91
  • 143
  • 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? – Brad Adams Jul 22 '16 at 13:21
  • I'm also getting "count that was removed" + 1. Any help? I've put that code in `applicationDidBecomeActive` AND `applicationDidFinishLaunchingWithOptions` – Terence Feb 09 '17 at 14:04
  • 1
    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. – Marcus Adams Feb 09 '17 at 14:49
3

For Swift 3.0

//AppleDelgate.swift
 func applicationDidBecomeActive(_ application: UIApplication) {
        //....
        application.applicationIconBadgeNumber = 0
       //....
}