我正在嘗試清除我的應用程序的「未讀」徽章,其中包含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