UILocalNotification接收带有NSYearCalendarUnit的repeatInterval的通知(将开火日期移动到下一个开火日期)

时间:2014-05-13 12:42:18

标签: ios uilocalnotification

我将通知的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

1 个答案:

答案 0 :(得分:0)

您应该更新通知的开火日期。

试试这个:

// 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];