从Apple Server获取日期和时间 [英] Get Date and Time from Apple Server

查看:113
本文介绍了从Apple Server获取日期和时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个只能在一天中的特定时间使用的应用程序.我无法获取本地设备时间,因为用户可以轻松更改设备时间,从而可以在一天中的任何时间访问应用程序.

I'm developing an app that can only be used during a certain time of the day. I can't get the local device time because the user can easily change the device time thereby allowing access to the application for any time of the day.

有没有办法从Apple服务器获取当前日期和时间(如果没有的话)还有其他方法吗?

Is there a way to get the current date and time from an Apple server (or if not,) is there any other way?

推荐答案

我认为您应该使用Internet时间服务器.他们正在使用称为 NTP 的标准化协议. iOS具有内置支持,可读取NTP服务器时间,但这无法访问作为应用程序开发人员.您可以自己实现,也可以使用开放源代码库,例如 ios-ntp HS NTP .我本人还没有使用过它们.检查设备的位置并找出时区,以获得真正的防弹解决方案可能是个好主意.

I think that you should be using an Internet time server. They are using a standardized protocol called NTP. The iOS has built-in support for reading NTP server time, but this is not accessible to you as an application developer. Either you implement this yourself, or you could maybe use an open source library, like ios-ntp or HS NTP. I have not used any of them myself. It is probably a good idea to check the position of the device and figure out the timezone, to get a real bulletproof solution.

在这里您可以阅读有关服务器和相关内容的更多信息; NIST互联网时间服务

Here you could read more about the servers and stuff; NIST Internet Time Service

理想情况下,您应该在应用程序中具有服务器列表.如果其中一个失败,则调用列表中的下一个NTP服务器.

Ideally, you should have a list of servers in the application. If one of them fails, you call the next NTP server in the list.

这篇关于从Apple Server获取日期和时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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