When the push notification is received, the didReceiveRemoteNotification method of the App Delegate is called and then we can perform the required action and clear the badge.


Code

/**
 * Remote Notification Received while application was open.
 */
– (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
       
    #if !TARGET_IPHONE_SIMULATOR
     NSString *badge = [apsInfo objectForKey:@"badge"];
    NSLog(@"Received Push Badge: %@", badge);

     // set it to Zero will clear it.
     [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

    #endif
}