Check if the device datesettings is automatic in iOS

The way iOS is structured, your app lives in a sandbox and can only communicate with the system if there is a public API that Apple has shared with the developer community. Some public APIs can be used freely like the accelerometer but others require user permission like the location information. Unfortunately the date and time settings apis are not public and so you can't play with the date and time settings at all.

There are many posts about getting the time in a user tamper proof way. The bottom line is that there is no real 100% tamper proof solution but the following code is already a good step for protecting from most users.

#import <CoreLocation/CoreLocation.h>

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

Many other resources but take a look at these two:

  • http://www.earthtools.org/webservices.htm#timezone
  • http://www.timeapi.org/utc/now

You can use this tool https://github.com/instacart/TrueTime.swift to get a synchronized time.

If you really want to ask the user, then you can compare the synchronized date to current date Date(). If the date is very different then you can ask the user to check settings.

Tags:

Ios

Swift