我正在尝试清除我的应用程序的“未读”徽章,其中包含UILocalNotification
。从逻辑上讲,你会认为这会通过设置UILocalNotification
实例applicationIconBadgeNumber
0做,但它不工作,并为applicationIconBadgeNumber文档说“默认值是0,表示”没有变化“。”清除当地通知的应用程序徽章
所以真的没有办法清除与本地通知徽章一旦它被设置
更新:一些简单的代码:
-(void)applicationDidFinishLaunching
{
// Set the appication icon badge to 1 in 10 minutes, using a local notification so it works in the background:
// This works fine.
UILocalNotification *episodeNotification = [[UILocalNotification alloc] init];
episodeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:(60 * 10)];
episodeNotification.timeZone = [NSTimeZone defaultTimeZone];
episodeNotification.applicationIconBadgeNumber = 1;
[[UIApplication sharedApplication] scheduleLocalNotification:episodeNotification];
[episodeNotification release];
// Clear the application icon badge in 20 minutes, again using a local notifcation so it works in the background:
// This doesn't work. According to the docs for local notification it's not supposed to
// because (applicationIconBadgeNumber = 0) means "Do not change the badge"
// I'm looking for an alternative if it exists.
UILocalNotification *clearEpisodeNotification = [[UILocalNotification alloc] init];
clearEpisodeNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:(60 * 20)];
clearEpisodeNotification.timeZone = [NSTimeZone defaultTimeZone];
clearEpisodeNotification.applicationIconBadgeNumber = 0;
[[UIApplication sharedApplication] scheduleLocalNotification:clearEpisodeNotification];
[clearEpisodeNotification release];
}
'...但它不工作,...'会发生什么,当你尝试设置徽章为零? – Moshe 2011-03-21 13:33:15
当我将徽章设置为零并且通知触发时,_nothing_发生。它继续显示与之前相同的号码。 – peterjb 2011-03-21 19:18:23
我们可以看一些代码吗? – Moshe 2011-03-21 19:32:14