Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear push notification badge count in iOS?

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; 
like image 731
Deepak Avatar asked Dec 26 '12 09:12

Deepak


People also ask

How do I clear badge count on iPhone?

Go to Settings and open Notifications. Scroll down and tap on Messages. To disable notifications altogether, toggle off Allow Notifications. To remove badges, turn off the toggle next to Badges.

What is iOS notification badge count?

The iOS badge count displays the number of unread notifications within your application, taking the form of a red circle in the upper-right hand corner of the app icon. In recent years, badging has come to be an effective means for re-engaging app users.


1 Answers

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) 
like image 147
Sumanth Avatar answered Oct 05 '22 23:10

Sumanth