从iOS应用图标中删除徽章 [英] Removing badge from iOS app icon
问题描述
在我正在尝试制作的这个应用程序中,我使用推送通知。这部分工作正常。当我发送通知时,我还会在应用图标上添加徽章。问题是,当我在午餐时,应该会再次消失,但事实并非如此。
In this application that I'm trying to make, I use push notifications. This part works just fine. When I send a notification I also add a badge to the app icon. The problem is when I lunch the application it should disappear again, but it does not.
-(IBAction)Push{
NSMutableDictionary *data = [NSMutableDictionary dictionary];
[data setObject:@"Numfeud: Troels made a move!" forKey:@"alert"];
[data setObject:[NSNumber numberWithInt:1] forKey:@"badge"];
[data setObject:@"bar" forKey:@"foo"];
[PFPush sendPushDataToChannelInBackground:@"GameChannel2" withData:data];
}
在应用程序中didFinishLaunchingWithOptions
我尝试以这种方式将徽章设置为0:
In the application didFinishLaunchingWithOptions
I try to set badge to 0 in this way:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
如何清除应用程序图标徽章?
How can I clear the application icon badge?
推荐答案
如果您的应用再次变为活动状态但仍处于后台,则应重置 -applicationDidBecomeActive:
中的徽章数量:
If your app becomes active again and is still in the background you should reset the badge count in -applicationDidBecomeActive:
as well:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
application.applicationIconBadgeNumber = 0;
}
如果您的应用仍然在后台运行 - application:didFinishLaunchingWithOptions:
将不会被调用。
If your app is still running in the background -application:didFinishLaunchingWithOptions:
won't be called.
这篇关于从iOS应用图标中删除徽章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!