8

For various reasons I need to get from the iPhone the current date and time that can't be meddled with by the user. Yes, I've seen how one can check a server (e.g., here), but that's not invulnerable to tampering if you take a moment to reflect.

There are two knee-jerk reactions I'm expecting to hear:

  1. Use the GPS time.
  2. It can't be done.

In answer to another question, I've described my researches into this matter. To summarize them:

  1. The GPS time shifts with the user-defined settings.
  2. The iPhone definitely has an internal tamper-proof time and date, as shown when date-time reverts after Set Automatically in Settings > General > Time & Date is turned back to on even in a fallout shelter.

What I want to know is how to access this tamper-proof time.


Edit

Just to be clear, the server-based solution is not suitable. For one, it could be faked. For another, the app needs to work without a network connection.

Community
  • 1
  • 1
JohnK
  • 6,865
  • 8
  • 49
  • 75
  • Please note that I'm not trying to get around the App-Store Review Guidelines. Also answers need not be App-Store compliant, though that would be preferred. – JohnK Jul 09 '13 at 23:50
  • No doubt the phone gets time from the carrier as it's main "automatic" source. This is not foolproof, however, as the carrier time can be off. – Hot Licks Jul 10 '13 at 00:55
  • @HotLicks, please note that a fallout shelter is a Faraday cage, into which no electromagnetic signal may pass. – JohnK Jul 10 '13 at 01:00
  • The phone likely maintains a separate clock, based on carrier time. – Hot Licks Jul 10 '13 at 02:25

1 Answers1

2

Assuming you always have Internet available, you could implement a class or object that connects to a remote Network Time Protocol server.

Here's an open source GitHub project that should get you started, and the related StackOverflow question I found it at.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Thanks for your quick response, Michael! Please consult the second sentence of my question. – JohnK Jul 10 '13 at 00:02
  • Thanks for the quick shootdown of my attempt to be helpful. AFAIK, NTP time isn't necessarily the same thing as GPS time. I suppose if somebody was incredibly determined, they could do a man-in-the-middle technique and spoof the IP address of whatever server you're calling and return some maliciously adjusted time value. – Michael Dautermann Jul 10 '13 at 00:05
  • No offense meant: I did thank you for the quickness of your response, which is also an excuse for missing a sentence in the question. Your second thought is exactly my thought, thought there are also other ways. I just wonder why the GPS time has to change with the manual adjust--the problem would be so much easier if it didn't. – JohnK Jul 10 '13 at 00:11
  • Changing the time zone does not change the time. It changes the way the time is *displayed* (e.g, 5 PM in US/Pacific time becomes 6 PM in US/Mountain time), but both names identify the same point in time. –  Jul 10 '13 at 00:14
  • @MichaelDautermann is correct. NTP time is a similar format to what you get with `NSDate` (which means that it doesn't care about time zones, it only stores the number of seconds since January 1, 1900 00:00 Z) – borrrden Jul 10 '13 at 00:57
  • @duskwuff (and borrrden): you are exactly right, though I'm not sure of the relevance of your observations. I'm not talking about adjustment of `Time Zone`, but about `Set Date & Time`. – JohnK Jul 10 '13 at 01:03