問題描述
我的應用程序可以在設備時區更改時收到任何通知嗎?我想在我的應用程序處于前臺時收到通知.NSTimezone 對我不起作用,因為我必須不斷檢查時區.
can my application get any notification when device timezone changed? I want to get a notification when my application is foreground. NSTimezone does not worked for me as i have to continuously check for timezone.
推薦答案
UIApplicationDelegate
有一個名為 applicationSignificantTimeChange:
的方法,當時間發生重大變化時會調用該方法.
UIApplicationDelegate
has a method called applicationSignificantTimeChange:
that gets called when there is a significant change in the time.
文檔中列出的示例是:
重大時間變化的示例包括午夜的到來、運營商的時間更新以及夏令時的變化
Examples of significant time changes include the arrival of midnight, an update of the time by a carrier, and the change to daylight savings time
但我認為時區變化算作重大的時間變化.
But I would assume that timezone changes count as a significant time change.
文檔還說,如果在您的應用處于后臺時發生時間變化,您將在您轉到前臺時得到它
The docs also say that if the time change happens when your app is in the background you will get it when you go to the foreground
如果您的應用程序當前處于掛起狀態,則此消息將排隊等待您的應用程序返回到前臺,此時它會被傳遞.
If your application is currently suspended, this message is queued until your application returns to the foreground, at which point it is delivered.
您還可以偵聽要發布的 UIApplicationSignificantTimeChangeNotification
以在您應用的其他任何地方獲取相同的信息.
You can also listen for UIApplicationSignificantTimeChangeNotification
to be posted to get the same information anywhere else in your app.
這篇關于在 iOS 中獲取有關時區更改的通知的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!