【问题标题】:Local Notifications set specific fire date本地通知设置具体的开火日期
【发布时间】:2014-07-20 02:49:23
【问题描述】:
我正在制作一个具有本地通知功能的 iOS 应用。我想要做的是将本地通知的触发日期设置为特定日期。例如:通知将于 2014 年 7 月 28 日上午 10:31 发出。
[localNotification setFireDate:[NSDate dateWithTimeIntervalSinceNow:10]];
这就是我现在所拥有的,它将应用启动后的触发日期设置为 10 秒。那么如何将其设置为确切的日期?
提前致谢!
【问题讨论】:
标签:
ios
objective-c
localnotification
【解决方案1】:
您可以从这样的组件创建日期:
NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.minute = 31;
dateComponents.hour = 10;
...
NSDate *fireDate = [[NSCalendar autoupdatingCurrentCalendar] dateFromComponents:dateComponents];