iPhone sdk:如何增加本地通知数量

发布于 2024-10-21 17:40:26 字数 1041 浏览 6 评论 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];

}

谢谢

Hi I am working on Google calendar, I have to remain user events with local notifications, when event starts.

for that I have to show notifications, if user have two events at a time then local notification count has to increase on app icon.(If I have two events at a time also count is showing only one local notification count on the app icon).

please suggest me how to increase the local notification count on the app icon.

please check my code.

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

}

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦巷 2024-10-28 17:40:26

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

[UIApplication sharedApplication].applicationIconBadgeNumber = count;

Assuming that the variable count contains the correct number to shown on the icon's badge, you simply do the following:

[UIApplication sharedApplication].applicationIconBadgeNumber = count;
魔法少女 2024-10-28 17:40:26

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

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

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: badgeSortCount]

my answer will need a database:

create an array (database) sorted with date and count. When a notification fires up, call it's count and display it using

[[UIApplication sharedApplication] setApplicationIconBadgeNumber: badgeSortCount]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文