IOS / Objective-C:UNNotificationRequest:如何处理时区

时间:2018-04-19 15:54:26

标签: ios objective-c unnotificationtrigger

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

0 个答案:

没有答案