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

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

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

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

前臺定位權(quán)限

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

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

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

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

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

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

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

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

參考:

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

注意:

requestWhenInUseAuthorization只有在用戶未選擇時會彈出對話框。

* When +authorizationStatus != kCLAuthorizationStatusNotDetermined, (ie

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

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

相關(guān)文章

最新評論