kraitz kraitz - 5 months ago 58
iOS Question

Get Date and Time from 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.

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


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 for 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 bullet proof solution.

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

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.