[英]Local notification set default time 9:00 am for user timezone in 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種方式完成
- (void)applicationSignificantTimeChange:(UIApplication *)應用程序
2。 在Notificationcenter中注冊UIApplicationSignificantTimeChangeNotification
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleTimeChange:)]
;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.