【问题标题】:Schedule a UILocalNotification every day at the same time每天在同一时间安排一次 UILocalNotification
【发布时间】:2014-05-29 20:37:23
【问题描述】:

我想在接下来的 20 天内每天 6:00、9:00、12:00 触发 UILocalNotification。 我意识到这个问题是一个非常基本的问题,我会尝试使用 NSDateComponents 来完成这个问题,但后来我意识到当一个月只有 28 天或年份变化时我可能会遇到问题。这就是为什么我要问:有没有人经历过这样的任务并可以给我一些提示?

【问题讨论】:

    标签: nsdate uilocalnotification


    【解决方案1】:

    使用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];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-10-10
      • 1970-01-01
      • 2018-02-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多