如何在工作日的选择列表中设置重复UILocal通知

iOS*_*dev 6 iphone objective-c localnotification uilocalnotification

我使用以下链接实现了UILocal Notification

http://useyourloaf.com/blog/2010/07/31/adding-local-notifications-with-ios-4.html

我已修改它以通过使用每天设置重复通知

//To set the repeat notification
            notif.repeatInterval = NSDayCalendarUnit;
Run Code Online (Sandbox Code Playgroud)

例如,每天早上10点

但我的要求是用户需要在选定的周日(星期一到星期六)设置通知

为什么因为用户可能有每周假期(周六和周日)/周五 - 周日)/其他一些日子 ..

在...上 week offs he shouldn't fire the notifications.

因此,我们祝贺用户设置所选的工作日,通知将仅在那些日期设置..一旦用户设置了通知.

For ex:

我们有工作日Sun,MOn,星期二,星期三,星期四,星期五,星期六的清单

这些用户选择星期一,星期二,星期四,星期四.并设定在10Am

然后通知将在这些天的每天上午10点开启.

怎么做

Pau*_*l.s 8

UILocalNotification的API在这方面非常有限 - 您必须在用户选择的日期手动安排每周重复的4个事件.

为星期一安排重复计时器的示例将如下所示

NSDateComponents *dateComponents = [[NSDateComponents alloc] init];
dateComponents.weekday = 2; // sunday = 1 ... saturday = 7
dateComponents.hour    = 10;

UILocalNotification *notification = //...
notification.repeatInterval = NSWeekCalendarUnit;
notification.fireDate       = [calendar dateFromComponents:dateComponents];
Run Code Online (Sandbox Code Playgroud)

可以在NSDateComponents类参考中找到日期编号