How to clear badge counter on click of app icon in iphone?

To clear the badge count whenever the application becomes active use delegate method. You can use UIApplicationDelegate in AppDelegate.

call the [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; in either applicationWillEnterForeground nor applicationDidBecomeActive

- (void)applicationWillEnterForeground:(UIApplication *)application

{
 [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
 }

or

- (void)applicationDidBecomeActive:(UIApplication *)application
{
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

Swift

func applicationWillEnterForeground(application: UIApplication) {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}

or

func applicationDidBecomeActive(application: UIApplication) {
UIApplication.sharedApplication().applicationIconBadgeNumber = 0
}

For Swift 3:

UIApplication.shared.applicationIconBadgeNumber = 0

iOS 13 >

func sceneDidBecomeActive(_ scene: UIScene) {
UIApplication.shared.applicationIconBadgeNumber = 0
}

enter image description here


If you are on iOS 13 supporting multiple windows, do the same on the method Scene Became active like this. This method is on SceneDelegate.

func sceneDidBecomeActive(_ scene: UIScene) {
    UIApplication.shared.applicationIconBadgeNumber = 0;
}

In Swift the following works to put in func applicationWillEnterForeground(application: UIApplication):

UIApplication.sharedApplication().applicationIconBadgeNumber = 0