NSLocationAlwaysUsageDescription string added in info.plist is not showing in permission popup ios

风流意气都作罢 提交于 2019-12-08 15:55:44

问题


<key>NSLocationAlwaysUsageDescription</key>
    <array>
        <string>Location is required to find out where you are</string>
    </array>
    <key>Privacy-Location Usage Description</key>
    <string>Location is required to find out where you are.</string>

I have added this in info.plist. Still the permission popup does not shows the string added,Instead it shows-- Allow "app" to access your location even when you are not using the app?


回答1:


Use CLLocationManager

  • Add the following line in your Info.plist file (right clic -> Open as -> Source Code)

    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your explanation</string>
    
  • Add the CLLocationManagerDelegate to your swift file

    class ViewController: UIViewController, CLLocationManagerDelegate {...}
    
  • In your viewDidLoad() function, write the following lines :

    var locationManager : CLLocationManager = CLLocationManager()
    locationManager.delegate = self
    locationManager.requestAlwaysAuthorization()
    

It should work ! Hope I helped you !



来源:https://stackoverflow.com/questions/38278220/nslocationalwaysusagedescription-string-added-in-info-plist-is-not-showing-in-pe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!