iPad日期时间设置更改时通知应用程序 [英] Notify app when iPad date time settings changed

查看:408
本文介绍了iPad日期时间设置更改时通知应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在更改ipad的日期时间设置时收到通知。那有什么办法吗?

I would like to get notified when ipad's date-time settings is changed. Is there any way for that?.

我正在使用NSDateFormatter来查找iPad / iphone时间模式是12或24小时格式。 NSDateFormatter似乎需要花费大量时间(见时间分析)。所以我想检查只在更改设置时才使用它。

I am using NSDateFormatter to find whether iPad/iphone time mode is 12 or 24 hr format. NSDateFormatter is seems to take lots of time( seen in time profiling). So I would like to check use it only when settings is changed.

推荐答案

你可以用两种方式来做:

You can do it using two ways:


  1. 在您的应用中实施 - (void)applicationSignificantTimeChange:(UIApplication *)应用委托。

  2. 添加观察员UIApplicationSignificantTimeChangeNotification

  1. Implement - (void)applicationSignificantTimeChange:(UIApplication *)application in your app delegate.
  2. Add a observer for UIApplicationSignificantTimeChangeNotification

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(timeChanged :) name:UIApplicationSignificantTimeChangeNotification object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(timeChanged:) name:UIApplicationSignificantTimeChangeNotification object:nil];




applicationSignificantTimeChange:

告知代表当时间发生重大变化。
- (void)applicationSignificantTimeChange :( UIApplication *)application

Tells the delegate when there is a significant change in the time. - (void)applicationSignificantTimeChange:(UIApplication *)application

参数

Parameters

应用程序

The delegating application object.

讨论

重要时间变化示例包括午夜到来,b $ b b由运营商更新时间,以及夏令时变化
时间。委托可以实现此方法来调整
的任何对象,该应用程序显示时间或对时间变化敏感。

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. The delegate can implement this method to adjust any object of the application that displays time or is sensitive to time changes.

在调用此方法之前,应用程序还会发布
UIApplicationSignificantTimeChangeNotification通知,让
感兴趣的对象有机会响应更改。

Prior to calling this method, the application also posts a UIApplicationSignificantTimeChangeNotification notification to give interested objects a chance to respond to the change.

如果您的应用程序当前已暂停,则此消息为排队
直到你的应用程序返回到前台,此时它是
。如果发生多次时间更改,则只有最近一次更改为
。可用性

If your application is currently suspended, this message is queued until your application returns to the foreground, at which point it is delivered. If multiple time changes occur, only the most recent one is delivered. Availability

Available in iOS 2.0 and later.

在UIApplication.h中声明

Declared In UIApplication.h

有关详细信息,请访问 UIApplicationDelegate_Protocol

For more check UIApplicationDelegate_Protocol

这篇关于iPad日期时间设置更改时通知应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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