views:

580

answers:

2

Hi,

I'm looking for a reliable way to get the time. It can't be tampered with and it needs to work offline. So no internet time , no user time setup in settings and no BSD uptime time since last reboot. I was wondering since GPS works using atomic clock, whether I could access that information.

Thank you

+1  A: 

This gets you the current date and time:

NSDate *now = [NSDate date];

This will be as reliable as you can get. The internal clock on the iPhone will be updated when it can get access to an NTP server. If the phone uses GPS as a time sync source it'll also be used to update the same system-wide clock which is accessible via the above method.

The CoreFoundation equivalent is something like:

CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();

Which returns the CoreFoundation equivalent of the normal UNIX seconds-since-epoch timestamp.

Benno
A: 

Even if you can get hold of the time from GPS you should be aware that GPS time is not quite the same as UTC. The GPS receiver in the iPhone might take care of that for you though.

Kevin ORourke