2013-10-15 29 views
1

在我的應用程序中,我有觸發本地通知的對象。iOS >>本地通知>>添加到應用程序的徽章號​​碼雖然應用程序在後臺

當應用程序在後臺時,本地通知會在被解僱的時候觸發,並且工作正常。

由於某些原因,徽章號碼未更新。

當設置通知的對象,我使用下面的代碼:

UILocalNotification* localNotification = [[UILocalNotification alloc] init]; 

localNotification.fireDate = obj.noteMeDate; //obj is an object for which the notification is created... 
localNotification.alertBody = [NSString stringWithFormat:@"Note: %@", obj.title]; 
localNotification.alertAction = @"Show Me"; 
localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
localNotification.soundName = UILocalNotificationDefaultSoundName; 
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1; //this is NOT WORKING... 

[[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 

有人嗎?

回答

0

您不能增加徽章數量,您只能將其設置爲某個數字。當您安排通知時,applicationIconBadgeNumber爲0(因爲您在前臺運行應用程序),因此每個通知在徽章中只顯示1個。

+0

有沒有辦法在應用程序在後臺時對任何事件做出反應?我的意思是,它似乎仍然在某個地方「活躍」。沒有辦法指示應用程序對通知作出反應嗎? –

+0

嘗試使用後臺任務API。 –

0

從技術上講,你不能直接增加徽章圖標,但有一種方法。

int num = [UIApplication sharedApplication].applicationIconBadgeNumber; 

[UIApplication sharedApplication].applicationIconBadgeNumber = num + 1; 
相關問題