iOS清空推送消息badge

1、清除手机APP上的角标badge

- (void)applicationWillEnterForeground:(UIApplication *)application {
    [application setApplicationIconBadgeNumber:0];
    [application cancelAllLocalNotifications];
}

这种方式会删除角标但同时也会删除通知栏的通知信息
2、还有一种方式 只会清除角标但是不会清除通知栏的信息

//不在appIcon上显示推送数量,但是在系统通知栏保留推送通知的方法
#define isIOS11 ([[UIDevice currentDevice].systemVersion floatValue] >= 11)

-(void)resetBageNumber{
  if(isIOS11){
    /*
     iOS 11后,设置badgeNumber = -1就生效了
     */
    [UIApplication sharedApplication].applicationIconBadgeNumber = -1;
  }else{
    UILocalNotification *clearEpisodeNotification = [[UILocalNotification alloc] init];
    clearEpisodeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:(0.3)];
    clearEpisodeNotification.timeZone = [NSTimeZone defaultTimeZone];
    clearEpisodeNotification.applicationIconBadgeNumber = -1;
    [[UIApplication sharedApplication] scheduleLocalNotification:clearEpisodeNotification];
  }

}


你可能感兴趣的:(iOS清空推送消息badge)