Is there a way to determine the actual time and date in iOS (not the time of the device)

自古美人都是妖i 提交于 2019-12-01 14:07:05

问题


In iOS, I need to know the actual time (UTC), not the time of the device. In other words, it should not be possible for the user to tamper with the time or date.

Anything that requires a network connection is not good (so accessing a time server is not an option).

AFAIK, there are 2 theoretical ways of achieving this:

  • Use the timestamp from the GPS satellite signal
  • Get the current time from the carrier

Problem is that this information is not exposed by any API in iOS.

Is there another way?


回答1:


Most solutions you could possibly find (including getting GPS data from CoreLocation to access the time information) are flawed because they are depending on the actual device to access time time. You will need to connect to a time server (i would suggest to check for NTP server). I was looking at the core telephony framework and couldn't find anything that would provide the network time. You might want to fill a bug report and request apple to expand one of the classes to include the time.




回答2:


You could have a look at secondsFromGMTForDate: and secondsFromGMT in NSTimeZone. If the GMT offset increases/decreases when the time of the device is changed, these provide a way to correct your timestamps to GMT (and probably convert to UTC).




回答3:


You can't get to the raw GPS data and the timestamp property of the CLLocation in locationManager:didUpdateLocations: is set with the system clock



来源:https://stackoverflow.com/questions/12006245/is-there-a-way-to-determine-the-actual-time-and-date-in-ios-not-the-time-of-the

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!