【发布时间】:2014-05-29 20:37:23
【问题描述】:
我想在接下来的 20 天内每天 6:00、9:00、12:00 触发 UILocalNotification。 我意识到这个问题是一个非常基本的问题,我会尝试使用 NSDateComponents 来完成这个问题,但后来我意识到当一个月只有 28 天或年份变化时我可能会遇到问题。这就是为什么我要问:有没有人经历过这样的任务并可以给我一些提示?
【问题讨论】:
标签: nsdate uilocalnotification
我想在接下来的 20 天内每天 6:00、9:00、12:00 触发 UILocalNotification。 我意识到这个问题是一个非常基本的问题,我会尝试使用 NSDateComponents 来完成这个问题,但后来我意识到当一个月只有 28 天或年份变化时我可能会遇到问题。这就是为什么我要问:有没有人经历过这样的任务并可以给我一些提示?
【问题讨论】:
标签: nsdate uilocalnotification
使用repeatInterval 创建三个不同的本地通知。
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
localNotification.fireDate = date; // Specifly date and time for notification
localNotification.repeatInterval = NSCalendarUnitDay;
localNotification.alertBody = @"Notification";
localNotification.timeZone = [NSTimeZone defaultTimeZone];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
在 20 天后取消这些通知。
[[UIApplication sharedApplication] cancelAllLocalNotifications];
or
[[UIApplication sharedApplication] cancelLocalNotification:NOTIFICATION_ID];
【讨论】: