[英]Clearing the badge when received Push Notification
How can I clear the badge which appears on application icon when I receive Push Notification?收到推送通知时,如何清除应用程序图标上显示的徽章? I want to clear it once user has either tapped on "View" of Push notification alert or has tapped on the app icon.
一旦用户点击了推送通知警报的“查看”或点击了应用程序图标,我想清除它。
I suspect you are talking about the SpringBoard's badge:我怀疑您在谈论 SpringBoard 的徽章:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
Badge count set Zero徽章计数设置为零
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
Cancel all local notifications with this code:使用此代码取消所有本地通知:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
Cancel one local notification with this line of code:使用这行代码取消一个本地通知:
[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
here theNotification is a UILocalNotification object, so in order to cancel a specific notification, you need to hold on to it's UILocalNotification.这里的Notification是一个UILocalNotification object,所以为了取消一个特定的通知,你需要抓住它的UILocalNotification。
For Mac OS X Lion, it's:对于 Mac OS X Lion,它是:
[NSApp dockTile].badgeLabel = @"";
(Lion supports badge-type push notifications.) (Lion 支持徽章类型的推送通知。)
From Apple's documentation, set the application.applicationIconBadgeNumber
to the number you want displayed on the badge.从 Apple 的文档中,将
application.applicationIconBadgeNumber
设置为您希望在徽章上显示的数字。 If you set it to 0, it will be cleared.如果将其设置为 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;
}
Reference - Scroll down to the Handling Local and Remote Notifications section just above listing 2.4 参考 - 向下滚动到清单 2.4 上方的处理本地和远程通知部分
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.