iPhone sdk:如何增加本地通知数量
您好,我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设变量 count 包含图标徽章上显示的正确数字,您只需执行以下操作:
Assuming that the variable count contains the correct number to shown on the icon's badge, you simply do the following:
我的答案需要一个数据库:
创建一个按日期和计数排序的数组(数据库)。当通知触发时,调用它的计数并使用
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