IOS/Objective-C: UNNotificationRequest: How to handle time zones

671 Views Asked by At

The old (pre IOS10.0) API for notifications had a property for timezone so that the notification would adjust to time zones.

The new API UNNotifications does not seem to have a time zone property.

Does this mean, you are just supposed to ignore time zones? Or how would you reproduce the same behavior that was in the old LocalNotifications when you set a time zone.

//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

There are 0 best solutions below