是否有替代ios-ntp来获得原子/当前时间ios? [英] Is there an alternative to ios-ntp to get atomic/ current time ios?

查看:517
本文介绍了是否有替代ios-ntp来获得原子/当前时间ios?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中,我想获得准确的日期和时间,基本上,在我的应用程序中,将会有一个时间敏感部分,用户在一定时间之后才能启动。

In my app I want to get the accurate date and time , Basically, in my application there is going to be a time sensitive portion that users can not start until after a certain time.

但如果我从设备中获取日期和时间,用户可以轻松更改设备上的日期和时间,设置> ;一般>时间与日期在这里更改。

But if I go and grab the date and time from the device, the user can easily change the date and time on their device, Settings > General > Time & Date change it here.

我也试过GPS位置时间戳,但没有运气, [CLLocation timeStamp] 也提供设备时间,

I also tried with GPS locations time stamp but no luck, [CLLocation timeStamp] is also give device time,

我搜索了所有说使用 ios-ntp ,但不是用户没有网络连接时,

I have searched all said to use ios-ntp, but it is not when user not have internet connection,

我推荐以下StackOverflow问题:

I have refer following StackOverflow questions:

  • Accurate time on iPhone
  • Network Time Protocol for iPhone
  • Is there any way to get the tamper-proof date and time on iPhone?
  • Retrieving Current Time from Carrier in iPhone
  • Time-based syncing for iOS app

但未获得结果I想要,

还有其他方法可以获得准确/实际的时间吗?

Is there other way to get accurate/ actual time ?

注意: ios必须将currentdate存储在某个位置,因为当我从设置更改当前系统日期时,再次设置为设置>一般>时间与日期>自动设置> ON 它将设置当前的准确日期,那么我们可以获得该日期吗?或者一些技巧?

NOTE : ios have to store the currentdate some where , because when i change current system date from settings , and again set to Settings > General > Time & Date > set automatically > ON it will set the current accurate date, so can we get that date ?? or some trick ?

示例:

假设现在在设备中是 2014-01-01 15:04:57 +0000 (现在自动设置为开启在设置>常规>时间和日期>自动设置>开),
现在

用户设置自动设置> OFF 并将当前日期更改为 2014-03-02 11:14:32 +0000

Suppose that In device right now time is 2014-01-01 15:04:57 +0000 ( right now set automatically is ON in Settings > General > Time & Date > set automatically > ON ), now
user set set automatically > OFF and change current dateto 2014-03-02 11:14:32 +0000

SO在应用程序中我写 NSLog(@cdate:%@,[NSDate date]); 它将打印

SO when in app i write NSLog(@"cdate: %@",[NSDate date]); it will print

cdate:2014-03-02 11:14:32 +0000 但我想要的是打印当前的实际

cdate: 2014-03-02 11:14:32 +0000 but what i want is to print the current actual

日期 2014-01-01 15:04:57 +0000

推荐答案

你是否意识到你在问不可能?如果您需要花时间并且没有网络连接,那么唯一可以获得时间的地方就是设备。要么您信任设备时间,要么从NTP获得时间。没有其他选择。

Do you realise you are asking the impossible? If you need to get the time and you don't have network connectivity, the only place to get the time from is the device. Either you trust the device time, or you get the time from NTP. There are no other choices.

你如何处理这取决于你需要花时间的确切原因。如果你的应用程序中有一些功能绝对不能在特定日期之前启用,我会从外部服务器获取时间,如果证明是在上述日期之后,请在默认设置中设置一个标记,表示您已经过验证允许使用日期和功能,因此您之后不需要网络连接。如果没有网络连接,则不设置标志,但可能会发出一条消息,说明您需要连接到Internet以启用新功能。

How you handle this depends on exactly why you need to get the time. If, there is functionality in your app that absolutely must not be enabled before a certain date, I would get the time from an external server and if it proves to be after the said date, set a flag in your defaults to say you have verified the date and the functionality is allowed, so you don't need to network connectivity thereafter. If the networking connectivity is not there, you don't set the flag but maybe put a message up to say that you need to connect to the Internet to enable the new functionality.

如果它只是游戏的某些部分,请使用设备时间,让他们在需要时作弊。

If it's just some part of a game, use device time and let them cheat if they want.

这篇关于是否有替代ios-ntp来获得原子/当前时间ios?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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