问题描述:最近在项目中集成了极光推送,接收通知后,发现手机上的app图标右上角一直有个红色的数字1无法清除,但是在代码中已经设置了使角标清除的方法。
通过测试发现,如果收到通知后点击通知栏进入app,则角标会清除;
如果收到通知后直接点击app图标或者设置方法使得接收通知后直接跳转页面进入app,则角标不会清除;
解决方法如下:
//程序在运行时收到通知,点击通知栏进入app
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(NSInteger))completionHandler {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService setBadge:0];
}
//程序在后台时收到通知,点击通知栏进入app
- (void)jpushNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
[JPUSHService setBadge:0];
//点击App图标,使App从后台恢复至前台
- (void)applicationWillEnterForeground:(UIApplication *)application {
[application setApplicationIconBadgeNumber:0];
[application cancelAllLocalNotifications];
}
//按Home键使App进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application{
[application setApplicationIconBadgeNumber:0];
[application cancelAllLocalNotifications];
}
注意:(1) [UIApplication sharedApplication].applicationIconBadgeNumber = 0;
(2) [JPUSHService setBadge:0];/[application cancelAllLocalNotifications];
//清除所有通知这两个方法要同时使用才能清除本地图标和远程的通知!