UILocationNotification不遵守夏令时 [英] UILocationNotification not obeying daylight savings
问题描述
我正在安排像这样的本地通知
I am scheduling local notifications like so
+ (void) addLocalNotification: (Event *) event {
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.fireDate = event.scheduleTime;
localNotif.alertBody = @"Time to apply drops\nPlease press view to see details";
localNotif.soundName = ALARM_SOUND_FILE;
localNotif.timeZone = [NSTimeZone localTimeZone];
localNotif.applicationIconBadgeNumber = 1;
NSDictionary * dict = [NSDictionary dictionaryWithObjectsAndKeys:event.number,LN_EVENT_KEY, ACTION_EVENT, LN_ACTION_KEY, nil];
localNotif.userInfo = dict;
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
然而,在上周末时钟前进之后,在时钟前进之前排定的通知将在一个小时后触发,即19:00而不是18:00
However after the clocks went forward this last weekend, the notifications scheduled before the clocks went forward are firing an hour later, ie 19:00 instead of 18:00
苹果文档说要获取挂钟"时间,请按上述设置时区.
The apple documentation says to get "wall clock" time set the time zone as above.
欢迎任何建议.
推荐答案
因此,与其添加我使用过的24小时时间间隔..
So rather than adding a time interval of 24 hours I have used ..
+ (NSDate *) addOneDayToDate: (NSDate *) date {
return [currentCalendar dateByAddingComponents:oneDay toDate:date options:0];
}
其中
oneDay = [[NSDateComponents alloc] init];
[oneDay setDay:1];
currentCalendar = [NSCalendar currentCalendar];
在大多数情况下,这是可行的,除非日期在午夜到时钟通常在凌晨2:00之间更改的时间.不需要逻辑,因为日期时间将在此之后.
This works in most cases unless the date is between midnight and the time the clocks change usually around 2:00am. Have not needed logic for this since the date times will be after this.
这篇关于UILocationNotification不遵守夏令时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!