'Getting error in debugger: This app has attempted to access privacy-sensitive data without a usage description

I'm having an issue in the debug area. It's saying that: "This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both “NSLocationAlwaysAndWhenInUseUsageDescription” and “NSLocationWhenInUseUsageDescription” keys with string values explaining to the user how the app uses this data."

The app I'm creating involves obtaining the user's location only when s/he is using the app, or in other words, only in the foreground. I've only added in my info.plist: Key(Privacy - Location When In Use Usage Description), Type(String), Value(We'll use your location to find jobs near you!).

Here is the code in my view controller:

import UIKit
import Foundation
import CoreLocation

class JobTableViewController: UITableViewController, CLLocationManagerDelegate {
    
let locationManager = CLLocationManager()

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    
// Implement Indeed Job Search API
    let headers = [
        "x-rapidapi-host": "indeed-indeed.p.rapidapi.com",
        "x-rapidapi-key": "838897ae8cmsha8fef9af0ee840dp1be982jsnf48d2de3c84a"
    ]

    let request = NSMutableURLRequest(url: NSURL(string: "https://indeed-indeed.p.rapidapi.com/apigetjobs?v=2&format=json")! as URL,
                                            cachePolicy: .useProtocolCachePolicy,
                                        timeoutInterval: 10.0)
    request.httpMethod = "GET"
    request.allHTTPHeaderFields = headers

    let session = URLSession.shared
    let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
        if (error != nil) {
            print(error!)
        } else {
            let httpResponse = response as? HTTPURLResponse
            print(httpResponse!)
        }
    })

    dataTask.resume()
   
    
// Recieve live location from user
    // For use when the app is open
    locationManager.requestWhenInUseAuthorization()
    
    if CLLocationManager.locationServicesEnabled() {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.startUpdatingLocation()
    }
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    if let location = locations.first {
        print(location.coordinate)
    }
}

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
    if(status == CLAuthorizationStatus.denied) {
        showLocationDisabledPopUp()
        
    }
}

// If user disabled location services
func showLocationDisabledPopUp() {
    let alertController = UIAlertController(title: "Location Access is Disabled", message: "In order to automatically find jobs near you, we need your location.", preferredStyle: .alert)
    
    let cancelAction = UIAlertAction(title: "Okay", style: .cancel, handler: nil)
    alertController.addAction(cancelAction)
    
    let openAction = UIAlertAction(title: "Open Settings", style: .default) { (action) in
        if let url = URL(string: UIApplication.openSettingsURLString) {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
    }
    alertController.addAction(openAction)
    
    self.present(alertController, animated: true, completion: nil)
    
}

I am able to successfully build the app and log in to the app. The debugger even successfully shows the coordinates of the simulator. However, it still gives me this warning and I am unable to use the coordinates to find nearby jobs through the API that I installed (which the code is also included above). I don't know why it's even warning me about "NSLocationAlwaysAndWhenInUseUsageDescription" since it's not mentioned once in my program.

Is there a legit reason for this warning? Also, is this warning connected to the fact that the app is unable to provide nearby jobs via the API? I know that this is all very confusing, so I've attached screenshots of everything below. Please ask any questions for clarification and thanks so much for all of your help!

info.plist screenshot debugger screenshot



Solution 1:[1]

The debugger message and the other two answers tell you what you need to do. Add the additional usage key with the same text.

Why? This is required because as of iOS 12 a user can respond "when in use" when asked for "always" and in iOS 13 will only get asked for "when in use" when an app first asks for "always".

Prior to iOS 12, the different "when in use" and "always" permission request strings are used depending on what your app asks for.

In iOS 12 and later you need to have a usage string that make sense in both an "always" and "when in use" scenario in a single key.

Apple provides the new NSLocationAlwaysAndWhenInUseUsageDescription Key to allow app developers an opportunity to provide different information in light of the new behaviour.

In theory this is the only key that is required after iOS 12, but for backward compatibility you are required to include both the old and new keys, even if your minimum ios target is iOS 12 or later.

Solution 2:[2]

Just add both the keys NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription inside info.plist, locations services will start completely fine.

Solution 3:[3]

For fetching location updates from the user's device you need to ask for the user's permission. If not asked, Apple will reject the app when the app is submitted for review.

Add these two keys in info.plist -

NSLocationWhenInUseUsageDescription
name - Privacy - Location When In Use Usage Description
reason - why your app wants to access location
NSLocationAlwaysAndWhenInUseUsageDescription
name - Privacy - Location Always and When In Use Usage Description
reason - why your app wants to access location

Solution 4:[4]

In my case is forget set Privacy - Location When In Use Usage Description in Info.plist

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Paulw11
Solution 2 Coder
Solution 3 Ashish Chauhan
Solution 4 Papon Smc