xcode MKMapView 确实失败并出现错误:Error Domain=kCLErrorDomain Code=1“(null)”

Dom*_*Dev 2 xcode dictionary ios swift mobile-development

我在 xcode 中编写地图时遇到以下错误:

\n
2021-01-09 19:02:48.228694+0100 BudapestBoards[31795:558225] Metal API Validation Enabled\n2021-01-09 19:02:48.433777+0100 BudapestBoards[31795:558225] This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an \xe2\x80\x9cNSLocationWhenInUseUsageDescription\xe2\x80\x9d key with a string value explaining to the user how the app uses this data\n2021-01-09 19:02:50.483788+0100 BudapestBoards[31795:558499] [MKCoreLocationProvider] CLLocationManager(<CLLocationManager: 0x600002b2b5b0>) for <MKCoreLocationProvider: 0x600001b30360> did fail with error: Error Domain=kCLErrorDomain Code=1 "(null)"\nCoreSimulator 732.18.6 - Device: iPhone 12 Pro Max (B1F529FE-C1E7-4C0A-B918-A3C76E006F27) - Runtime: iOS 14.3 (18C61) - DeviceType: iPhone 12 Pro Max\n
Run Code Online (Sandbox Code Playgroud)\n

我正在使用mapview。\n我的代码是:

\n
import UIKit\nimport MapKit\nimport CoreLocation\n \nclass ViewController: UIViewController, CLLocationManagerDelegate {\n    @IBOutlet weak var mapView: MKMapView!\n    let manager = CLLocationManager()\n    override func viewDidLoad() {\n        super.viewDidLoad()\n    }\n    override func viewDidAppear(_ animated: Bool) {\n        super.viewDidAppear(animated)\n        manager.desiredAccuracy = kCLLocationAccuracyBest\n        manager.delegate = self\n        manager.requestWhenInUseAuthorization()\n        manager.startUpdatingLocation()\n        func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {\n            if let location = locations.first {\n                manager.stopUpdatingLocation()\n                render(location)\n            }\n        }\n        func render(_ location: CLLocation) {\n            let span = MKCoordinateSpan(latitudeDelta: 0.1, longitudeDelta: 0.1)\n            let coordinate = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)\n            let region = MKCoordinateRegion(center: coordinate, span: span)\n            mapView.setRegion(region, animated: true)\n        }\n    }\n    \n}\n
Run Code Online (Sandbox Code Playgroud)\n

感谢您在添加 NSLocationWhenInUseUsageDescription 时做出回应,它说它已经存在于字典中,如果我想替换它。如果我按替换,除了删除该行之外,它不会执行任何操作。

\n

D. *_*ika 5

该错误中的相关信息是:

\n
\n

此应用试图在没有使用说明的情况下访问隐私敏感数据。\n 应用的 Info.plist 必须包含\n\xe2\x80\x9cNSLocationWhenInUseUsageDescription\xe2\x80\x9d 键以及字符串值\n向用户解释应用如何使用此数据

\n
\n

您需要在您的应用程序中提供一个字符串Info.plist来解释为什么您的应用程序想要访问位置信息。

\n

因此找到该Info.plist文件,添加一个新行“NSLocationWhenInUseUsageDescription文件,添加一个以“ ”为键和文本该文本显示在警报中,询问用户是否允许访问,因此请考虑对其进行本地化。

\n