ios - xcode MKMapView 确实失败,错误为 : Error Domain=kCLErrorDomain Code=1 "(null)"

标签 ios swift xcode dictionary mobile-development

我在 xcode 中编写 map 时遇到这些错误:

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

我正在使用 map View 。 我的代码是:

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 时做出回应,它说它已经存在于字典中,如果我想替换它。如果我按替换,除了删除该行之外,它不会执行任何操作。

最佳答案

该错误的相关信息为:

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

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

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

关于ios - xcode MKMapView 确实失败,错误为 : Error Domain=kCLErrorDomain Code=1 "(null)",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65646013/

相关文章:

ios - iTunes 收据验证 - in_app 为空

ios - 如何为 iOS Mobile SDK 生成许可证 key

ios - 使用 uipageviewcontroller Xcode 创建书本类型翻转动画

ios - 移动第三方文件夹后找不到“config.h”文件

ios - 如何在不重定向通用登录页面的情况下直接在 Auth0 中登录?

iOS7 UIPickerView - 触摸进入后台 subview

ios - 防止 Xcode 每次都构建子项目

ios - 如何在 iOS 中以编程方式在日历中添加事件的超链接而不显示实际 URL?

ios - viewDidAppear 时突出显示

iOS UITableView 滚动到部分底部