1

用于通知的旧(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";
4

0 回答 0