首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >多排定LocalNotification

多排定LocalNotification
EN

Stack Overflow用户
提问于 2014-06-22 19:33:57
回答 1查看 260关注 0票数 0

是否有可能在目标-c中制作多个预定的LocalNotifications?

代码语言:javascript
复制
NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *dateComponent = [calendar components:NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit fromDate:[NSDate date]];

    [dateComponent setYear:2014];
    [dateComponent setMonth:6];
    [dateComponent setDay:28];
    [dateComponent setHour:10];
    [dateComponent setMinute:48];

    UIDatePicker *dp = [[UIDatePicker alloc]init];
    [dp setDate:[calendar dateFromComponents:dateComponent]];

    UILocalNotification *notification = [[UILocalNotification alloc]init];
    [notification setAlertBody:@"Hello"];
    //[notification setFireDate:[NSDate dateWithTimeIntervalSinceNow:3]];
    [notification setFireDate:dp.date];
    [notification setTimeZone:[NSTimeZone defaultTimeZone]];
    notification.soundName = UILocalNotificationDefaultSoundName;
    notification.soundName = @"Song2.caf";
    notification.applicationIconBadgeNumber = -1;
    [application setScheduledLocalNotifications:[NSArray arrayWithObject:notification]];

我试着重复这个过程,但是没有成功,我只是做了最后一个,所以我能做的就是一个预定的LocalNotification。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-22 20:02:40

是的。

使用

代码语言:javascript
复制
[application scheduleLocalNotification:notification];

若要为每个通知对象设置通知而不是setScheduledLocalNotifications:[NSArray arrayWithObject:notification],请执行以下操作。

如果需要设置非常多的通知,可以在初始化和设置通知数组后将所有通知添加到通知数组中:

代码语言:javascript
复制
[application setScheduledLocalNotifications:[NSArray arrayWithObjects:notification1, notification2, notification3]];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24354949

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档