Reputation: 20148
I need to be able to get the absolute time the from the iOS device (iPhone 5.0 +)
I used CLLocation timestamp property, but that is not working like I thought it would.
If the user is in an area where the time is 16:45, but for whatever reason the user sets the time manually to 21:00, I want to be able to get the 16:45 time from the device and not the 21:00.
So, how can I get the absolute time from within my app, so that the user has no way to make the app think that it's whatever time he sets in the settings?
EDIT: I am looking to see if there is a way to obtain this without having to ping an external server??
Thank you
Upvotes: 1
Views: 1209
Reputation: 9911
You probably want to query a timeserver on the internet to get time independently of the time the user has set the device to. There are some libraries that may be able to help with this: ios-ntp and HS NTP.
If you're looking for the users localtime, you'll also need to get the users location, and figure out their timezone based on this. And then take care of things like daylight savings/summer time - it's a non-trivial thing to do, as different countries (and states/islands in countries) around the world have their daylight savings switchover at different dates and times.
Upvotes: 4