UILocalNotification is supposed to repeat every weekday, but fires on weekends as well

后端 未结 4 1002
无人共我
无人共我 2020-12-28 09:36

I have a UILocalNotification that is supposed to fire once a day, Monday through Friday, but not on the weekend. I thought that setting the repeatInterval property of the no

4条回答
  •  抹茶落季
    2020-12-28 10:31

    Weekday in iOS just means a day inside of a week. It doesn't have the "work week" connotation as opposed to a weekend.

    The documentation says it a little clearer, by suggesting that you use 1-7 as the units:

    NSWeekdayCalendarUnit

    Specifies the weekday unit.

    The corresponding value is an kCFCalendarUnitSecond. Equal to kCFCalendarUnitWeekday. The weekday units are the numbers 1 through N (where for the Gregorian calendar N=7 and 1 is Sunday).

    Source: http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html

    To properly set your notifications from Monday through Friday, here's some skeleton code. Yo'll have to execute it 5 times, so it'd be good to encapsulate it inside of a method that parameters for the fireDate. I've shown how you could do it for Monday.

    UILocalNotification *notification = [[[UILocalNotification alloc] init] autorelease];
    
    // Set this to an NSDate that is for the time you want, on Monday
    notification.fireDate = fireDate;            
    
    // Repeat every week
    notification.repeatInterval = NSWeekCalendarUnit;
    

提交回复
热议问题