2011-03-12 14 views
0

您好我正在使用Google日曆,當事件開始時,我必須保留包含本地通知的用戶事件。iPhone sdk:如何增加本地通知計數

因爲我必須顯示通知,如果用戶一次有兩個事件,那麼本地通知計數必須增加應用程序圖標。(如果我一次有兩個事件,count也只顯示一個本地通知計數在應用程序圖標)。

請建議我如何增加應用程序圖標的本地通知計數。

請檢查我的代碼。

//Local notifications delegates and methods. 
Class cls = NSClassFromString(@"UILocalNotification"); 

if (cls != nil) { 

UILocalNotification *notif = [[cls alloc] init]; 
notif.fireDate = [[when startTime] date]; 
notif.timeZone = [NSTimeZone defaultTimeZone]; 

// Notification details 
notif.alertBody = titles;// here title is the key word for the event 

// Set the action button 
notif.alertAction = nil; 
notif.soundName = UILocalNotificationDefaultSoundName; 
notif.applicationIconBadgeNumber = 1; 


// Specify custom data for the notification 
NSDictionary *userDict = [NSDictionary dictionaryWithObject:titles forKey:kRemindMeNotificationDataKey]; 

notif.userInfo = userDict; 

// Schedule the notification 
[[UIApplication sharedApplication] scheduleLocalNotification:notif]; 
[notif release]; 

} 

謝謝

回答

0

假設變量count包含正確的數量上的圖標徽章顯示,你只需做到以下幾點:

[UIApplication sharedApplication].applicationIconBadgeNumber = count; 
0

我的回答將需要一個數據庫:

創建按日期和次數排序的數組(數據庫)。當通知啓動時,請將其計數並使用

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: badgeSortCount]