收到推送通知时清除徽章
答
我怀疑你是在谈论跳板的徽章:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
答
从苹果公司的文件,设置application.applicationIconBadgeNumber
到要显示的徽章的数量。如果将它设置为0,它将被清除。
- (BOOL)application:(UIApplication *)app didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if (localNotif) {
NSString *itemName = [localNotif.userInfo objectForKey:ToDoItemKey];
[viewController displayItem:itemName]; // custom method
application.applicationIconBadgeNumber = localNotif.applicationIconBadgeNumber-1;
}
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES;
}
答
对于Mac OS X Lion中,它是:
[NSApp dockTile].badgeLabel = @"";
(狮子支持徽章式推送通知。)
答
徽章计数设为零
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
取消所有本地通知与此代码:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
取消一个本地通知,这行代码:
[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
这里所述通知是UILocalNotification对象,所以为了消除特定的通知,需要坚持它的UILocalNotification。
检查this。