Is there a way to check if the device settings for "date and time" is set to automatic or not in Swift? And if there is, is there possible to make the User to switch to the desired settings (automatic)
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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With