【问题标题】:xcode MKMapView did fail with error: Error Domain=kCLErrorDomain Code=1 "(null)"xcode MKMapView 确实失败并出现错误:Error Domain=kCLErrorDomain Code=1 "(null)"
【发布时间】:2021-04-15 03:57:54
【问题描述】:

我在 xcode 中编写地图时遇到了这些错误:

2021-01-09 19:02:48.228694+0100 BudapestBoards[31795:558225] Metal API Validation Enabled
2021-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 “NSLocationWhenInUseUsageDescription” key with a string value explaining to the user how the app uses this data
2021-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)"
CoreSimulator 732.18.6 - Device: iPhone 12 Pro Max (B1F529FE-C1E7-4C0A-B918-A3C76E006F27) - Runtime: iOS 14.3 (18C61) - DeviceType: iPhone 12 Pro Max

我正在使用地图视图。 我的代码是:

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

感谢您在添加 NSLocationWhenInUseUsageDescription 时做出回应,它说它已经存在于字典中,如果我想替换它。如果我按下替换它除了删除该行之外什么都不做。

【问题讨论】:

    标签: ios swift xcode dictionary mobile-development


    【解决方案1】:

    这个错误中的相关信息是:

    此应用试图在没有 使用说明。应用的 Info.plist 必须包含 带有字符串值的“NSLocationWhenInUseUsageDescription”键 向用户解释应用如何使用这些数据

    您需要在info.plist 中提供一个字符串,说明您的应用为什么要访问位置信息。

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

    【讨论】:

      猜你喜欢
      • 2015-10-29
      • 2021-09-28
      • 2015-05-19
      • 2011-08-27
      • 2017-06-27
      • 1970-01-01
      • 1970-01-01
      • 2016-10-14
      • 2019-01-31
      相关资源
      最近更新 更多