检查系统时间是自动还是用户设置 [英] Check if system time is auto or user set

查看:105
本文介绍了检查系统时间是自动还是用户设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在当前项目中设置用户证明时间。我发现了很多不同的问题,但没有一个似乎有我想要的答案。这些是我到目前为止所看到的问题:

I need to set up user proof time keeping in my current project. I have found a lot of different question around this, but none that seem to have the answer I am looking for. These are the questions i have looked at so far:

XCODE:如何获取/验证来自设备的ACCURATE时间戳

是否可以从iphone GPS获取原子钟时间戳?

如何在iPhone中获取实时,而不是用户在设置中设置的时间?

我有几种方法可以从服务器连接中获取时间,但我也需要一个离线解决方案。

I have several options for getting a time from a server connection but I need to have an offline solution too.

1。
似乎使用CLLocation获得与设备时钟相同的时间。有没有获得实际的GPS时间?

1. It seems that using CLLocation gets the same time as as the device clock. Is there away to get the actual GPS time?

2。
我知道系统时间设置不是公共API,因此无法更改。是否可以确定设备是否已打开自动时间设置?如果自动时间打开,那么我可以依赖系统时间用于我的目的,如果它已经关闭然后记录,那么我知道记录的时间不值得信任吗?

2. I know the system time settings are not a public API thus can't be changed. Is it possible to find out if the device has the auto time setting turned on? If the auto time is on then I can rely on the system time for my purposes and if it's off then record that so I know that the time recorded is not to be trusted?

推荐答案

只是想发布我的解决方案,因为其他人有同样的问题。

Just wanted to post my solution, incase some one else has the same issue.

经过大量研究后我发现获得GPS时间设置信息无法进行。

After much research i found that getting GPS time of time setting info was not possible.

这个解决方案不是完美的,也不是实时的,但适用于我的目的。

This solution isn't perfect nor real time but works for my purpose.

我已实施了一段时间每次应用程序上线时使用云时间检查。当设备重新建立服务器连接以同步离线创建的事件时,我已经进行了验证,该验证采用最后的对象设备时间和新的对象设备时间并计算两者之间的经过时间。 (使用NSdates以便涵盖夏令时)然后对最后一个可用服务器时间和最近服务器时间执行相同操作。然后我比较结果,如果它们不在我的误差范围内,则事件被标记为无效。

I have implemented a time check using cloud time each time the app comes on line. When the device re-establishes a server connection to sync events created off line i have put a verification that takes the last object device time and the new object device time and calculates the elapsed time between the two. (using NSdates so that daylight savings is covered) then do the same with the last available server time and the most recent server time. I then compare the results and if they are not within my margin of error the events are marked as invalid.

希望这有意义并且对其他人有帮助。

Hope that makes sense and is helpful for others.

这篇关于检查系统时间是自动还是用户设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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