获取有关iOS时区变化的通知

获取有关iOS时区变化的通知

本文介绍了获取有关iOS时区变化的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序可以在设备时区更改时收到通知吗?我希望在我的应用程序是前台时收到通知。 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.

文档中列出的示例包括:

The examples listed in the documentation are:

但我认为时区变化算是一个重要的时间变化。

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

如果您的应用程序当前处于暂停状态,则此消息将排队,直到您的应用程序返回到前台,此时它将被传递。

您还可以收听 UIApplicationSignificantTimeChangeNotification ,以便在您的其他任何地方获取相同的信息app。

You can also listen for UIApplicationSignificantTimeChangeNotification to be posted to get the same information anywhere else in your app.

这篇关于获取有关iOS时区变化的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-27 23:28