繁体   English   中英

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

[英]Scheduled local notification and timezone changes in iOS

我的应用程序中有此方法可以触发计划的本地通知:

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

谢谢

您可以通过2种方式完成

  1. 在您的appdelegate中实现以下方法
  • (void)applicationSignificantTimeChange:(UIApplication *)应用程序

2。 在Notificationcenter中注册UIApplicationSignificantTimeChangeNotification

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTimeChange:)]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM