Darren
Darren

Reputation: 10129

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 holidays. 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.

Upvotes: 1

Views: 827

Answers (1)

James Webster
James Webster

Reputation: 32066

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.

Upvotes: 1

Related Questions