ios - NSLocationWhenInUseUsageDescription 错误继续显示
问题描述
我试图在我的项目中实现 MapKit 和 CoreLocation。不幸的是,错误一直显示
此应用程序试图在没有使用说明的情况下访问隐私敏感数据。应用的 Info.plist 必须包含一个 NSLocationWhenInUseUsageDescription 键和一个字符串值,向用户解释应用如何使用这些数据
所以这是我的代码和info.plist
import Foundation
import CoreLocation
import MapKit
class ViewController: UITabBarController, CLLocationManagerDelegate{
let locationManager: CLLocationManager = CLLocationManager()
@IBAction func backBarButton(_ sender: Any) {
self.dismiss(animated: true, completion:nil)
}
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
}
}
作为源代码 info.plist 打开
<key>NSLocationWhenInUseUsageDescription</key>
<string>accept to get location</string>
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>description</string>
<key>NSLocationUsageDescription</key>
<string>description</string>
打开 .plist 作为属性视图
我尝试创建一个新项目并且它运行顺利,但是当我尝试在现有项目上实现它时它不起作用。
解决方案
从 iOS 11 开始,您不能在不提供“When in Use”的情况下请求“Always”:如果您只设置 Privacy – Location Always Usage Description,它将不会出现,并且您将收到错误消息“Info.plist must contain和NSLocationAlwaysAndWhenInUseUsageDescription
钥匙NSLocationWhenInUseUsageDescription
……”。在 Xcode 9 beta 中,我必须使用NSLocationAlwaysAndWhenInUseUsageDescription
密钥;Xcode 不会选择匹配的隐私密钥。
位置经理要求“始终”:
推荐阅读
- java - Spring Boot 在运行时根据请求端点/请求参数注入 bean
- excel - 在 Excel 中取消选中“复选框”
- python - 解析 postgresql -pycparser.plyparser.ParseError 之前:pgwin32_signal_event
- apache-spark - 如何按分区对RDD进行操作?
- java - 我们如何在 Solr 中获取集群级别的指标?
- javascript - 使用 Firebase 函数处理传入数据
- node.js - 从 NodeJS 到 Amazon S3 的不完整文件复制
- database - 尝试打开 //usr/local/lib/x86_64-linux-gnu/libngsmshd12.so 失败
- wpf - MVVM OnpropertyChange UI 更改延迟
- ajax - Yajra\Datatables\Engines\CollectionEngine 类的对象无法转换为字符串