检查设备日期设置在iOS中是否是自动的 [英] Check if the device datesettings is automatic in iOS

查看:87
本文介绍了检查设备日期设置在iOS中是否是自动的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法检查Swift中日期和时间"的设备设置是否设置为自动? 如果可以的话,可以使用户切换到所需的设置(自动)

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)

推荐答案

iOS的结构方式,您的应用程序位于沙盒中,并且只有在Apple已与开发人员社区共享了公共API的情况下,才能与系统通信.某些公共API可以像加速度计一样自由使用,而其他API则需要用户许可,例如位置信息.不幸的是,日期和时间设置api不是公开的,因此您根本无法使用日期和时间设置.

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.

关于以用户防篡改方式获取时间的帖子很多.最重要的是,没有真正的100%防篡改解决方案,但是下面的代码已经是防止大多数用户使用的好步骤.

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

这篇关于检查设备日期设置在iOS中是否是自动的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆