我试图在我的项目中实现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开始,如果不提供“何时使用”,则无法请求“始终”:如果您仅设置隐私 - 位置始终使用说明,则不会显示,并且您将收到错误消息“Info.plist必须包含NSLocationAlwaysAndWhenInUseUsageDescription
和NSLocationWhenInUseUsageDescription
钥匙......“。在Xcode 9 beta中,我不得不使用NSLocationAlwaysAndWhenInUseUsageDescription
键; Xcode不会选择匹配的Privacy密钥。
位置经理要求“始终”: