在 iOS 中获取有关时区更改的通知 [英] get notification on timezone change in iOS

查看:24
本文介绍了在 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.

文档中列出的示例是:

重大时间变化的示例包括午夜的到来、运营商的时间更新以及夏令时的变化

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 中获取有关时区更改的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆