Ich möchte eine UILocalNotification
jeden Sonntag um 20 Uhr auslösen, aber ich habe ein Feuer Datum jeden Tag um 20 Uhr.Feuern Sie eine Benachrichtigung an einem bestimmten Tag und Uhrzeit jede Woche
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDate *now = [NSDate date];
NSDateComponents *componentsForFireDate = [calendar components:(NSYearCalendarUnit | 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] ;
NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];
UILocalNotification *notification = [[UILocalNotification alloc] init] ;
notification.fireDate = fireDateOfNotification ;
notification.timeZone = [NSTimeZone localTimeZone] ;
notification.alertBody = [NSString stringWithFormat: @"New updates!"] ;
notification.userInfo= [NSDictionary dictionaryWithObject:[NSString stringWithFormat:@"New updates added for that week!"] forKey:@"new"];
notification.repeatInterval= NSDayCalendarUnit ;
notification.soundName=UILocalNotificationDefaultSoundName;
NSLog(@"notification: %@",notification);//it indicates that the notif will be triggered today at 8PM and not Sunday.
[[UIApplication sharedApplication] scheduleLocalNotification:notification] ;
Vielen Dank.
versuchen Sie diese notification.repeatInterval = NSWeekCalendarUnit; – chancyWu
@Chany: Es springt auf die nächste Woche (nächsten Dienstag), aber nicht am Sonntag. Hier ist, was ich mit 'NSWeekCalendarUnit' habe:' next fire date = Dienstag, 26. November 2013 um 20:00 Uhr ' – androniennn