How to clear push notification badge count in iOS?

Deepak picture Deepak · Dec 26, 2012 · Viewed 41k times · Source

I want to clear the push notification badge count once app is launched.Im not clear where to set the below code.Please give brief description about clearing the badge count.

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

Answer

Sumanth picture Sumanth · Dec 26, 2012

You should set this:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

in either of these AppDelegate methods if the application is launched and sent to background then you launch the application didFinishLaunchingWithOptions method will not be called so use either of these methods:

- (void)applicationWillEnterForeground:(UIApplication *)application

- (void)applicationDidBecomeActive:(UIApplication *)application

For Swift 3+

- func applicationWillEnterForeground(_ application: UIApplication)
- func applicationDidBecomeActive(_ application: UIApplication)