Search code examples
iosobjective-ciphoneswiftios7

How to check the correct current time if user sets "Set Automatically" off


I have to check the correct current time if user sets "Set Automatically" off.

Is there any way to access the status of "Set Automatically" setting status so that I cam prompt user to turn it on. OR Another approach I can follow I can fetch the time from GPS(location) but the below code always gives the local time in case of user selects "Set Automatically" off.

CLLocation* location = [[CLLocation alloc] initWithLatitude:(CLLocationDegrees) 0.0 longitude:(CLLocationDegrees) 0.0];
NSDate* now = location.timestamp;

Is there any way to archive this behavior in ios.


Solution

  • If you can't rely on the local clock, you need to use an external source. There are (probably) several NTP-based libraries for this. For example: ios-ntp, which can currently be found here.