Я пытаюсь найти следующую дату огневого UILocalNotification
здесь кодОпределить UILocalNotification следующей дату пожара с другим часовым поясом
@implementation UILocalNotification (MyNextFireDate)
- (NSDate *)myNextFireDateAfterDate:(NSDate *)afterDate
{
// Check if fire date is in the future:
if ([self.fireDate compare:afterDate] == NSOrderedDescending)
return self.fireDate;
// The notification can have its own calendar, but the default is the current calendar:
NSCalendar *cal = self.repeatCalendar;
if (cal == nil)
cal = [NSCalendar currentCalendar];
// Number of repeat intervals between fire date and the reference date:
NSDateComponents *difference = [cal components:self.repeatInterval
fromDate:self.fireDate
toDate:afterDate
options:0];
// Add this number of repeat intervals to the initial fire date:
NSDate *nextFireDate = [cal dateByAddingComponents:difference
toDate:self.fireDate
options:0];
// If necessary, add one more:
if ([nextFireDate compare:afterDate] == NSOrderedAscending) {
switch (self.repeatInterval) {
case NSDayCalendarUnit:
difference.day++;
break;
case NSHourCalendarUnit:
difference.hour++;
break;
// ... add cases for other repeat intervals ...
default:
break;
}
nextFireDate = [cal dateByAddingComponents:difference
toDate:self.fireDate
options:0];
}
return nextFireDate;
}
@end
И этот код работает отлично, но если я изменить часовой пояс, то он начинает беспокоить , Я не знаю, как заставить его работать, когда изменяется часовой пояс.
Я устанавливаю defaultTimeZone
в моем UILocalNotification
здесь мой UILocalNotification
выглядит
{дата пожара = Пятница, 8 июля 2016 в 6:30:00 PM Индия Standard Time, часовой пояс = Азия/Калькутта (GMT + 5: 30) смещение 19800, интервал повторения = NSCalendarUnitHour, повторение count = UILocalNotificationInfiniteRepeatCount, next fire dat е = Пятница, 8 июля 2016 в 6:30:00 PM Central Daylight Time, информация о пользователе = {}
Пожалуйста, более конкретно, что вы имеете в виду, чтобы изменить часовой пояс – Feldur