1、清除手機APP上的角標badge
- (void)applicationWillEnterForeground:(UIApplication *)application {
[application setApplicationIconBadgeNumber:0];
[application cancelAllLocalNotifications];
}
這種方式會刪除角標但同時也會刪除通知欄的通知信息
2、還有一種方式 只會清除角標但是不會清除通知欄的信息
//不在appIcon上顯示推送數(shù)量,但是在系統(tǒng)通知欄保留推送通知的方法
#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];
}
}