Check if the device datesettings is automatic in iOS

后端 未结 2 603
闹比i
闹比i 2021-01-05 04:44

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 th

相关标签:
2条回答
  • 2021-01-05 04:55

    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
    0 讨论(0)
  • 2021-01-05 05:05

    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.

    0 讨论(0)
提交回复
热议问题