我在我的应用中使用此方法来触发预定的本地通知:
- (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
?
由于
答案 0 :(得分:0)
你可以用两种方式做到这一点
- (void)applicationSignificantTimeChange :( UIApplication *)application
2
。在notificationcenter中注册UIApplicationSignificantTimeChangeNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTimeChange:)]
;