欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

iOS11中的定位授權(quán)的解決方法

 更新時(shí)間:2018年02月12日 10:08:35   作者:吾身三省  
本篇文章主要介紹了iOS11中的定位授權(quán)的解決方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

本文介紹了iOS11中的定位授權(quán)的解決方法,分享給大家,具體如下:

前臺(tái)定位權(quán)限

1,增加NSLocationWhenInUseUsageDescription。
2,創(chuàng)建CLLocationManager對(duì)象,在使用定位服務(wù)前調(diào)用requestWhenInUseAuthorization()。
3,通過(guò)func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)處理權(quán)限變化。該函數(shù)并不會(huì)在每次改改變權(quán)限后都會(huì)被調(diào)用。

參考:
https://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services/requesting_when_in_use_authorization

前后臺(tái)定位權(quán)限

如果希望在app在前臺(tái)后臺(tái)都可以使用定位服務(wù),需要完成以下幾點(diǎn):

1,在plist中增加NSLocationWhenInUseUsageDescription和NSLocationAlwaysAndWhenInUsageDescription,如果需要支持iOS10的話,增加NSLocationAlwaysUsageDescription。

2,創(chuàng)建CLLocationManager對(duì)象,用requestWhenInUseAuthorization()獲得基本定位支持,用requestAlwaysAuthorization()獲得前后臺(tái)定位支持。

3,在第一次調(diào)用requestAlwaysAuthorization()時(shí),會(huì)提示NSLocationAlwaysAndWhenInUsageDescription中指定的文字,讓用戶選擇是升級(jí)到全權(quán)限還是,前臺(tái)權(quán)限。

4,通過(guò)func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)處理權(quán)限變化。該函數(shù)并不會(huì)在每次改改變權(quán)限后都會(huì)被調(diào)用。

參考:

https://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services/request_always_authorization

注意:

requestWhenInUseAuthorization只有在用戶未選擇時(shí)會(huì)彈出對(duì)話框。

* When +authorizationStatus != kCLAuthorizationStatusNotDetermined, (ie

* generally after the first call) this method will do nothing.

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論