0

嗨,我正在使用 Google 日历,当活动开始时,我必须在本地通知中保留用户活动。

为此我必须显示通知,如果用户一次有两个事件,则本地通知计数必须在应用程序图标上增加。(如果我一次有两个事件,计数也只在应用程序图标上显示一个本地通知计数) .

请建议我如何增加应用程序图标上的本地通知计数。

请检查我的代码。

//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];

}

谢谢

4

2 回答 2

0

假设变量 count 包含要显示在图标徽章上的正确数字,您只需执行以下操作:

[UIApplication sharedApplication].applicationIconBadgeNumber = count;
于 2011-03-12T06:45:31.940 回答
0

我的答案需要一个数据库:

创建一个按日期和计数排序的数组(数据库)。当通知触发时,调用它的计数并使用

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: badgeSortCount]
于 2011-03-12T11:13:12.413 回答