iOS如何检测用户已经改变了系统时间,如果没有将设备时间与服务器时间进行比较 [英] iOS how to detect user has changed system time, and if not compare device time with server time

查看:342
本文介绍了iOS如何检测用户已经改变了系统时间,如果没有将设备时间与服务器时间进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要求是必须检测用户是否手动更改iPhone的系统时间。为此,我使用了

The requirement is that have to detect if the system time of iPhone is changed by user manually. For that I have used

NSNotificationCenter.defaultCenter().addObserver(self, selector: "timeChangedNotification:", name: NSSystemClockDidChangeNotification, object: nil)

 func timeChangedNotification(notification:NSNotification){
    println("Device time has been changed...")
    }

但没有得到结果。
此外,如果此时间没有改变意味着它是由网络提供的自动时间,那么必须与服务器时间进行比较。如何做到这一点?请给予帮助。

But not getting the results. Also if this time is not changed means it is automatic time provided by network then have to compare with server time.How can this be done? Please give help for the same.

推荐答案

根据其文档, NSSystemClockDidChangeNotification is:


每当系统时钟发生变化时都会发布。这可以通过调用settimeofday()或用户更改日期和时间首选项面板中的值来启动。

Posted whenever the system clock is changed. This can be initiated by a call to settimeofday() or the user changing values in the Date and Time Preference panel.

因此,除非您希望用户在您的应用运行时更改日期或时间,否则您显然不会听到任何东西。通知由事件触发。

So unless you were expecting the user to change the date or time while your app is running, you're obviously not going to hear anything. Notifications are triggered by events.

iOS没有为您提供一种方式来询问系统认为时间和日期是当前值的权限 - 无论是运营商网络时间,时间服务器时间,用户提供的时间或其他。没有单一的服务器时间,也没有办法要求它。你不想做什么。

iOS doesn't provide you with a way to ask on whose authority the system believes the time and date is the current value — whether it's carrier network time, time server time, user-supplied time or something else. There's no single server time and no way to ask for it. What you want to do cannot be done.

这篇关于iOS如何检测用户已经改变了系统时间,如果没有将设备时间与服务器时间进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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