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中先使用以下的任何一行代码来获取定位权限,不过需要注意的是,这个代码只会生效一次:
剩下的见证奇迹吧。
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.
1 | // When in use or |
相关
更新内容
增加了对“使用 App期间和始终”权限和获取时机的补充描述。