You missed the NSWeekCalendarUnit
in the NSDateComponents
init function. Add the NSWeekCalendarUnit
to it and set the repeatInterval
to NSWeekCalendarUnit
, then output is
next fire date = Sunday, November 24, 2013 at 8:00:00 PM
The code is here:
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now = [NSDate date];
NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | NSWeekCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit| NSSecondCalendarUnit | NSWeekdayCalendarUnit) fromDate: now];
[componentsForFireDate setWeekday: 1] ; //for fixing Sunday
[componentsForFireDate setHour: 20] ; //for fixing 8PM hour
[componentsForFireDate setMinute:0] ;
[componentsForFireDate setSecond:0] ;
//...
notification.repeatInterval = NSWeekCalendarUnit;
//...
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…