开发者

UILocalNotification that repeats every weekday except holidays

I'm working on an iPhone app that requires a notification be presented at a given time every weekday. I've accomplished this by scheduling a UILocalNotification whose repeatInterval property is set to kCFCalendarUnitWeekday.

The problem is that the alert shouldn't be presented on hol开发者_StackOverflow社区idays. I have a list of 10 holidays maintained in a configuration file in my app. Is there a way to prevent the notification from being shown on these days? This notification should be presented when the app is running in the foreground or background, and preferably when it is closed, although I think that I could accept it not being shown when the app is closed.


I've copied this answer from this post: https://stackoverflow.com/posts/7257168/edit but remembered this question. It answers your question too

As you can see from the repeatInterval property, that you can specify only the predefined calendar units.

enum {
   NSEraCalendarUnit = kCFCalendarUnitEra,
   NSYearCalendarUnit = kCFCalendarUnitYear,
   NSMonthCalendarUnit = kCFCalendarUnitMonth,
   NSDayCalendarUnit = kCFCalendarUnitDay,
   NSHourCalendarUnit = kCFCalendarUnitHour,
   NSMinuteCalendarUnit = kCFCalendarUnitMinute,
   NSSecondCalendarUnit = kCFCalendarUnitSecond,
   NSWeekCalendarUnit = kCFCalendarUnitWeek,
   NSWeekdayCalendarUnit = kCFCalendarUnitWeekday,
   NSWeekdayOrdinalCalendarUnit = kCFCalendarUnitWeekdayOrdinal
   NSQuarterCalendarUnit = kCFCalendarUnitQuarter,
};

So, if you want the notification to repeat on any of these above intervals you can use the repeatInterval property with any of these values. But if you want the notification to repeat on intervals some like "Every Two Days" or on some irregular intervals, then you have to create individual notifications for each of those reminders.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜