Breaking News
Home / iOS / iOS Snippets / How to clear the iPhone number badge when the Push Notification Alert is recieved?

How to clear the iPhone number badge when the Push Notification Alert is recieved?

Snippet

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.

  1. /**
  2.  * Remote Notification Received while application was open.
  3.  */
  4. (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
  5.        
  6.         #if !TARGET_IPHONE_SIMULATOR
  7.          NSString *badge = [apsInfo objectForKey:@"badge"];
  8.         NSLog(@"Received Push Badge: %@", badge);
  9.  
  10.          // set it to Zero will clear it.
  11.          [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
  12.        
  13.         #endif
  14. }
[pb_builder]

Check Also

EKCalendar – That account does not allow calendars to be added or removed

Usecase When I am trying to create a new Calendar programmatically using the EventKit API …

Advertisment ad adsense adlogger