У меня есть метод, который делает магазин в UILocalNotification:UILocalNotification всегда установить дату для местного часового пояса
- (void)save:(NSString *)program at:(NSDate*)date {
NSLog(@"date to save: %@", date);
// NSLog(@"timezone: %@",[date descriptionWithLocale:[NSLocale systemLocale]]);
UILocalNotification* localNotification = [[UILocalNotification alloc] init];
NSLog(@"date to fire: %@", date);
localNotification.fireDate = date;
NSString *s=[program stringByAppendingString:@" is now on "];
NSString *title=[s stringByAppendingString:channel];
localNotification.alertBody = title;
localNotification.alertAction = @"Show...";
//localNotification.timeZone = [NSTimeZone localTimeZone];
localNotification.applicationIconBadgeNumber = [[UIApplication sharedApplication] applicationIconBadgeNumber] + 1;
NSLog(@"notification to save %@",localNotification);
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
// Request to reload table view data
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadData" object:self];
// Dismiss the view controller
[self dismissViewControllerAnimated:YES completion:nil];
}
И я, как выход:
date to save: 2013-08-29 17:00:00 +0000
date to fire: 2013-08-29 17:00:00 +0000
notification to save <UIConcreteLocalNotification: 0xc0c4240>{fire date = Thursday, August 29, 2013, 6:00:00 PM Central European Standard Time, time zone = (null), repeat interval = 0, repeat count = UILocalNotificationInfiniteRepeatCount, next fire date = Thursday, August 29, 2013, 6:00:00 PM Central European Standard Time, user info = (null)}
Несмотря раскомментирована настройка временной зоны, UILocalNotification всегда увеличивается на один час, почему и как? Спасибо, что помогли.
Благодарим вас за ответ. Но в этом случае все уведомления будут настроены на GMT. Я имею в виду, что если кто-то находится в GMT + 5, он получит уведомление в GMT, нет? – androniennn
Нет, iOS будет использовать вашу дату и время в соответствии с часовым поясом пользователя. См. Мое редактирование. – rckoenes
В этом случае вы назначаете действительный NSTimeZone для UILocalNotification (GMT), поэтому все уведомления будут отображаться в GMT, даже если человек не находится в GMT. Моя идея заключается в том, почему нельзя назначить 'localTimeZone' переданному значению и присвоить' localTimeZone' тоже объекту UILocalNotification? – androniennn