每14天(两周)后重复一次本地通知? [英] Repeating a Local Notification after every 14 days(two weeks)?
问题描述
在我的应用中,我要设置重复的 UILocalNotification
。我可以通过执行每日,每周等设置repeatInterval
In my app i've to set repetitive UILocalNotification
. I'm able to set repeatInterval as daily, weekly etc by doing
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.repeatInterval = NSDayCalendarUnit; // or any other calendarUnit
好的..没关系,但我要为每个设置repeatInterval 14天。
i来自此链接,我们知道了只能使用NSCalendarUnit重复间隔之一。因此,您可以重复间隔为一分钟或一小时或一天但不是五分钟或三小时或14天。关于iOS 5或更高版本中此限制的任何想法(该文章是为iOS 4.0编写的)?
Ok..it's fine, but i've to set repeatInterval for every 14 days. i came to know from this link that we can only use one of the NSCalendarUnit repeat intervals. So you can have a repeat interval of one minute or one hour or one day but not five minutes or three hours or 14 days. Any Idea about this limitation in iOS 5 or later(that article was written for iOS 4.0)?
推荐答案
您只能设置重复间隔到日历单位。为了获得正确的时间间隔,您可能需要设置几个通知。
You can only set the repeat interval to a calendar unit. In order to get the right time interval you may have to set several notifications though.
如果您例如每20分钟想要一个通知,则必须创建3个通知20分钟与NSHourCalendarUnit的重复间隔。
If you for instance wanted a notification every 20 minutes you would have to create 3 notifications 20 minutes apart with a repeat interval of NSHourCalendarUnit.
您的案例中的问题是,从周单位开始的下一件事是一个月,但一个月不完全是4周。
The problem in your case is that the next thing up from the week unit is a month but a month is not exactly 4 weeks.
要实际设置每14天的通知,您必须创建26个通知,重复间隔为NSYearCalendarUnit。
To actually set a notification for every 14 days you will have to create 26 notifications with a repeat interval of NSYearCalendarUnit.
这篇关于每14天(两周)后重复一次本地通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!