极光推送 角标清0 未读消息不清空

不要调用 [UIApplication sharedApplication].applicationIconBadgeNumber = 0; 

角标和通知栏未读推送都会清空

使用下面的方法。。。


- (void)applicationWillResignActive:(UIApplication *)application {

    /// 角标清0 未读推送不清空

    UILocalNotification *notification = [[UILocalNotification alloc] init];

    notification.applicationIconBadgeNumber = -1;

    [[UIApplication sharedApplication] presentLocalNotificationNow:notification];

    [JPUSHService setBadge:0];

}


- (void)applicationDidEnterBackground:(UIApplication *)application {

    

}


- (void)applicationWillEnterForeground:(UIApplication *)application {

    [application cancelAllLocalNotifications];

}

需要注意的是::方法一定要放对位置,如果放错位置会出现一些问题如下

遇到的问题: iOS11 APP运行于前台时,双击home键杀死APP,再次启动时启动页失效,,显示的是上次杀死时显示的页面,,APP推到后台再杀死APP,启动页正常

问题产生的原因:角标清0 未读推送不清空 的方法放错了地方

- (void)applicationDidEnterBackground:(UIApplication *)application {

    /// 角标清0 未读推送不清空

    UILocalNotification *notification = [[UILocalNotificationalloc] init];

    notification.applicationIconBadgeNumber = -1;

    [[UIApplicationsharedApplication] presentLocalNotificationNow:notification];

    [JPUSHService setBadge:0];

}


猜你喜欢

转载自blog.csdn.net/flg1554112450/article/details/79162253