我想使用自定义fireDate设置本地通知。它应该在每个星期天和星期一晚上7点发送。我住在欧罗巴。因为周历,我是否必须注意某些事情?
我的代码看着那样的时刻:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
NSDate *now = [NSDate date];
NSDateComponents *componentsForFireDate = [calendar components:(NSCalendarUnitYear | NSCalendarUnitHour | NSCalendarUnitMinute| NSCalendarUnitSecond | NSCalendarUnitWeekday) fromDate: now];
[componentsForFireDate setWeekday: 1] ;
[componentsForFireDate setHour: 19] ;
[componentsForFireDate setMinute:22] ;
[componentsForFireDate setSecond:0] ;
NSDate *fireDateOfNotification = [calendar dateFromComponents: componentsForFireDate];
// Create the notification
UILocalNotification *notification = [[UILocalNotification alloc] init] ;
notification.fireDate = fireDateOfNotification ;
notification.timeZone = [NSTimeZone localTimeZone] ;
notification.alertBody = [NSString stringWithFormat: @"Wake up"] ;
notification.soundName=UILocalNotificationDefaultSoundName;
修改
我记录了fireDate(2015-01-01 18:22:00 +0000)。首先它是一个小时到早,第二个是错误的日期)