iOS中一句话获取定位权限

iOS中一句话获取定位权限 A statement in iOS to request location permission

从 iOS 8开始需要用户分别给予在使用App期间(When in use)和始终(Always)的位置使用权限,而在最新的iOS系统中每个新App用户只能做出一次选择,选择了使用App期间,那么后续你也选择不了始终,选择了始终,那么无论你在使用App期间还是App为非当前使用App时均能使用你的位置(注意:这个时候在设置中App位置权限选择界面,你貌似有使用App期间和始终两个选项可选,然而无论你选择哪个选项效果都是一样的)。

在基于BaseViewController的控制器的-viewDidLoad中先使用以下的任何一行代码来获取定位权限,不过需要注意的是,这个代码只会生效一次:

剩下的见证奇迹吧。


For English here if you do not understand Chinese:

Starting from iOS 8, users are required to give permission of access to the location of "When in use" and "Always". However, in the latest iOS system, each new App user can only make a choice once. If you choose "When in use", then you cannot choose "Always" in the future. And if you choose "Always", you can use your location whether you are using the App or not (Note: If you choose "Always", in the Settings of the App privacy location selection, you seem to have two options to choose between "When in use" and "Always", however, no matter which option you choose, the effect is the same).

On the -viewDidLoad of the BaseViewControler based controller, use any line of the following codes first to request the location permission, but note that this code will only work once:

Just enjoy.

// When in use or
[self requestLocationAuthorization:YES];

// Always
[self requestLocationAuthorization:NO];

相关

  • 详见极致框架官网中使用位置部分的介绍。通过极致框架官网顶部的搜索功能搜索 EFBaseViewController。

许可

  • 本文采用 BY-NC-SA 许可协议。即:署名——转载请注明出处;非商业使用;相同方式传播——再分发的文章许可与原文相同。

查看原文

你可能感兴趣的:(iOS中一句话获取定位权限)