在 info.plist 中添加的 NSLocationAlwaysUsageDescription 字符串未显示在权限弹出 ios 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/38278220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 09:40:06  来源:igfitidea点击:

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

ioscllocationmanager

提问by Shilpa M

<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?

我在 info.plist 中添加了这个。权限弹出窗口仍然没有显示添加的字符串,而是显示 - 即使您不使用该应用程序,也允许“应用程序”访问您的位置?

回答by Damien Ballenghien

Use CLLocationManager

使用 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()
    
  • 在 Info.plist 文件中添加以下行(右键单击 -> 打开为 -> 源代码)

    <key>NSLocationAlwaysUsageDescription</key>
    <string>Your explanation</string>
    
  • 将 CLLocationManagerDelegate 添加到您的 swift 文件

    class ViewController: UIViewController, CLLocationManagerDelegate {...}
    
  • 在您的 viewDidLoad() 函数中,编写以下几行:

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

It should work ! Hope I helped you !

它应该工作!希望我能帮到你!