To know date and time settings in device from an iPhone application

后端 未结 2 2072
借酒劲吻你
借酒劲吻你 2021-01-14 23:36

I want to know whether the user has set their device to automatically set the date and time in the Settings.app in iPhone. I need this information because I want to make use

2条回答
  •  猫巷女王i
    2021-01-14 23:58

    I don't believe there exists a way to detect the user's preference regarding the automatic update of the date time settings. To determine the length of time from a given point, you have a few options none of which are absolute or without any error.

    1. Use NSDate, which you already know can be circumvented by manually changing the date on the device.
    2. Use a time server. By querying a time server you can get an independent date time value. Store that value and compare against it to determine if the right amount of time has passed. The drawback of course, is this requires an internet connection to function property.
    3. Use a system clock value or series of values to roughly calculate the time elapsed. A functions like CACurrentMediaTime or mach_absolute_time() can provide a count to compare against. You can take the values and increment them until you have reached a specified duration to reset a flag for your second day check.

    None of the options alone will provide an ideal solution, but by combining the approaches, you might achieve an acceptable level of assurance the user is accessing the information only during the time allowed.

提交回复
热议问题