用于通知的旧(IOS10.0之前版)API具有时区属性,因此通知将调整为时区。
新的API UNNotifications似乎没有时区属性。
这是否意味着,你应该忽略时区?或者,在设置时区时,如何重现旧LocalNotifications中的相同行为。
//New
NSDate *now = [NSDate date];
UNMutableNotificationContent *content = [UNMutableNotificationContent new];
content.title = [NSString localizedUserNotificationStringForKey:@"myalert" arguments:nil];
NSDateComponents *triggerDate = [[NSCalendar currentCalendar]
components:NSCalendarUnitYear +
NSCalendarUnitMonth + NSCalendarUnitDay +
NSCalendarUnitHour + NSCalendarUnitMinute +
NSCalendarUnitSecond fromDate:timeOfDate];
UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:triggerDate
repeats:NO];
UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"myalert" content:content trigger:trigger];
//Old:
reminderNotification = [[UILocalNotification alloc] init];
reminderNotification.fireDate = myDate;
reminderNotification.timeZone = [NSTimeZone defaultTimeZone];
reminderNotification.alertAction = @"Meeting begins";