当应用程序处于前台时,即使我将applicationBadgeNumber设置为0,当我退出应用程序时,仍有一个" 1"我的应用程序上的徽章,即使我杀了它,任何想法?当我在应用程序处于后台时打开通知时,完全没问题!
- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{
NSLog(@"%i", notification.applicationIconBadgeNumber); // Return 1
notification.applicationIconBadgeNumber = 0;
NSLog(@"%i", notification.applicationIconBadgeNumber); // Return 0
UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive)
{
// Application was in the background when notification
// was delivered.
}
else
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"An item is asking your attention" message:nil delegate:nil
cancelButtonTitle:@"Cancel" otherButtonTitles:@"Show me", nil];
[alert show];
}
}
答案 0 :(得分:7)
在我的应用中,点击图标即可确认任何未完成的通知。因此,当我关闭应用程序时,它始终会重置应用程序图标徽章编号。在app delegate中,添加一个方法来重置applicationWillResignActive
方法中的徽章编号,如下所示:
- (void) applicationWillResignActive:(UIApplication *)application
{
[application setApplicationIconBadgeNumber:0];
}
答案 1 :(得分:4)
你在哪里设置applicationBadgeNumber?我认为您正在设置通知徽章编号。
试试这个:
application.applicationIconBadgeNumber = 0;