【问题标题】:UILocalNotification receiving notification with repeatInterval of NSYearCalendarUnit (move fire date to next fire date)UILocalNotification 接收带有 NSYearCalendarUnit 的 repeatInterval 的通知(将触发日期移动到下一个触发日期)
【发布时间】:2014-05-13 12:42:18
【问题描述】:

我将通知的 repeatInterval 设置为 NSYearCalendarUnit。 当我收到通知时,我会看到我记录的以下通知信息:

fire date = Tuesday, 13 May, 2014... next fire date = Wednesday, 13 May, 2015

然后我取消通知,认为它会将火灾日期移至 2015 年 5 月 13 日

[application cancelLocalNotification:locationNotification];

但它没有......它真的取消了通知。

但是当我没有取消通知时,通知会保留但我的开火日期保持不变,我希望它移至 2015 年,下一个开火日期移至 2016 年

fire date = Tuesday, 13 May, 2014... next fire date = Wednesday, 13 May, 2015

【问题讨论】:

  • 您如何检查开火日期保持不变?我认为通过将您的设备日期更改为明年,即 2015 年 5 月 14 日并调试您的应用程序并检查触发日期是否更改。
  • 通过使用这个... NSArray *notifications = [[UIApplication sharedApplication] scheduledLocalNotifications];... NSLog(@"Notifications: %@", notifications);
  • 如上所述更改设备日期并再次检查。
  • 哈哈,我把我的设备换到明年了,但我的应用程序不能再运行了,我想是因为我的合同今年就要到期了……真的是因为这个吗?我的意思是一旦设备日期移到明年,开火日期就会移动?
  • 是的,对于调试,您可以将重复间隔设置为较短的时间段,如 1 分钟 1 天等,并通过更改设备日期/时间触发日期进行检查。

标签: ios uilocalnotification


【解决方案1】:

您应该更新通知的触发日期。

试试这个:

// Maybe in your code you don't need this, but I write it anyway
[application cancelLocalNotification:locationNotification];

// This will create a new date one year past the current notification fire date
NSDateComponents * components = [[NSDateComponents alloc] init];
components.year = 1;
NSDate * newDate = [[NSCalendar currentCalendar] dateByAddingComponents:components toDate:localNotification.fireDate options:kNilOptions];

// Now you can update the localNotification fire date
localNotification.fireDate = newDate;

// Schedule it. Again, maybe you don't need this in your code
[application scheduleLocalNotification:localNotification];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-03-16
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多