iOS中一句話獲取定位權限 A statement in iOS to request location permission
從 iOS 8開始需要用戶分別給予在使用App期間(When in use)和始終(Always)的位置使用權限珍策,而在最新的iOS系統(tǒng)中每個新App用戶只能做出一次選擇奥邮,選擇了使用App期間崇堵,那么后續(xù)你也選擇不了始終育韩,選擇了始終赞庶,那么無論你在使用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];
相關
- 詳見極致框架官網(wǎng)<extreme.framework/EFBaseViewController.h>中使用位置部分的介紹些举。通過極致框架官網(wǎng)頂部的搜索功能搜索 EFBaseViewController。
許可
- 本文采用 BY-NC-SA 許可協(xié)議俭厚。即:署名——轉載請注明出處户魏;非商業(yè)使用;相同方式傳播——再分發(fā)的文章許可與原文相同挪挤。