Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

xcode MKMapView did fail with error: Error Domain=kCLErrorDomain Code=1 "(null)"

I Had these errors while writing a map in 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

i am using mapview. my code is:

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)
        }
    }
    
}

Thanks for responding when adding a NSLocationWhenInUseUsageDescription it says it is already present in the dictionary and if i want to replace it. if i press on replace it does not do anything except delete that line.

like image 428
DominikDev Avatar asked Jun 13 '26 10:06

DominikDev


1 Answers

The relevant information in this error is:

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

You need to provide a string in your Info.plist that explains why your app wants to access location information.

So locate the Info.plist file, add a new line with "NSLocationWhenInUseUsageDescription" as key and a text. The text is presented in the alert which asks the user, whether he allows access or not, so consider localising it.

like image 161
D. Mika Avatar answered Jun 16 '26 08:06

D. Mika



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!