iOS中的计划本地通知和时区更改

iOS中的计划本地通知和时区更改,ios,timezone,scheduled-tasks,uilocalnotification,Ios,Timezone,Scheduled Tasks,Uilocalnotification,我在应用程序中使用此方法来触发计划的本地通知: - (void)scheduleNotificationForTime:(long long)atTime { NSDate *fireDate = [DatesMngr getDateFromLongLong:atTime]; UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) r

我在应用程序中使用此方法来触发计划的本地通知:

- (void)scheduleNotificationForTime:(long long)atTime
{
   NSDate *fireDate = [DatesMngr getDateFromLongLong:atTime];

   UILocalNotification *localNotif = [[UILocalNotification alloc] init];
   if (localNotif == nil)
       return;
   localNotif.fireDate = fireDate;
   localNotif.timeZone = [NSTimeZone localTimeZone];

   localNotif.alertBody = @"Active Status";
   localNotif.alertAction = @"View Details";
   localNotif.applicationIconBadgeNumber = 1;

   [[UIApplication sharedApplication] cancelAllLocalNotifications];
   [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
}
如果用户在设备设置中不更改时区,则可以正常工作,但如果用户在已计划但尚未启动时区后更改了时区,则不会启动通知。我还尝试了
[NSTimeZone defaultTimeZone]
,但没有成功。是否有任何方法可以检测这些时区更改并刷新已安排的本地通知的
fireDate


谢谢你可以用两种方法

  • 在appdelegate中实现以下方法
    • (无效)应用程序重要时间更改:(UIApplication*)应用程序
    二, . 在notificationcenter中注册
    UIApplicationsSignificantTimeChangeNotification


    [[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(HandleteMachage:)]

    谢谢,但只有在更改设备设置中的时区后,应用程序再次激活,并且我收到已安排的本地通知并重新设置其
    时区时,这才有效,对吗?如果用户只是更改时区,而在我希望启动通知之前她没有再次打开应用程序,该怎么办?