1
votes

I tried to implement MapKit and CoreLocation in my project. Unfortunately the error keep showing

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

so here's my code and 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()
    }
}

open as source code 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>

open .plist as property view

enter image description here

I tried to create a new project and it works smoothly, however when I tried to implement this on my existing project it doesn't work.

1
There is a possibility that the info.plist you are editing isn't the info.plist your app is using. I suggest you archive your app and then from the organiser window, select "show in finder" for the archive and "show contents" on the archive to see the info.plist that is actually being included. - Paulw11
@Paulw11make sense, let me try first - StevenTan
remove description - Vishal Vaghasiya

1 Answers

0
votes

As of iOS 11, you cannot request “Always” without offering “When in Use”: if you set only Privacy – Location Always Usage Description, it won’t appear, and you’ll get the error message “Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys…”. In Xcode 9 beta, I had to use the NSLocationAlwaysAndWhenInUseUsageDescription key; Xcode wouldn’t select the matching Privacy key.

the location manager requested “Always”:

click link for more description