You just need to properly create a NSDate
object to be your fire date (time). Instead of using [NSDate dateByAddingTimeInterval: 20]
, use something like this:
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay: 3];
[components setMonth: 7];
[components setYear: 2012];
[components setHour: 6];
[components setMinute: 0];
[components setSecond: 0];
[calendar setTimeZone: [NSTimeZone defaultTimeZone]];
NSDate *dateToFire = [calendar dateFromComponents:components];
Here are the Apple NSDateComponents API docs
And then when you add the date to the notification, set the repeat interval to one day:
[localNotification setFireDate: dateToFire];
[localNotification setTimeZone: [NSTimeZone defaultTimeZone]];
[localNotification setRepeatInterval: kCFCalendarUnitDay];
As with all date related code, make sure to test how this works during the switch to daylight savings time, if your time zone uses daylight savings time.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…