【发布时间】:2018-09-05 04:46:29
【问题描述】:
我尝试在我的项目中实现 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 作为属性视图
我尝试创建一个新项目,它运行顺利,但是当我尝试在现有项目上实现它时,它不起作用。
【问题讨论】:
-
您正在编辑的 info.plist 可能不是您的应用正在使用的 info.plist。我建议您存档您的应用程序,然后从管理器窗口中,为存档选择“在查找器中显示”并在存档中选择“显示内容”以查看实际包含的 info.plist。
-
@Paulw11有道理,我先试试
-
删除描述
标签: ios swift core-location