How to set the repeat UILocal Notifications on the select list of Weekdays

后端 未结 1 431
傲寒
傲寒 2020-12-06 03:28

I have implemented UILocal Notification using the following link

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

相关标签:
1条回答
  • 2020-12-06 03:51

    The API for UILocalNotification is very limited in this regard - you'll have to manually schedule 4 events repeating weekly on the days that the user selects.

    An example of scheduling a repeat timer for monday would look like this

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

    The day numbers can be found in the NSDateComponents Class Reference

    0 讨论(0)
提交回复
热议问题