Check if the device datesettings is automatic in iOS

后端 未结 2 604
闹比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 
    
    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

提交回复
热议问题