Good afternoon, for the past couple weeks I have been facing an issue in Xcode that says:
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
I have both of these usage descriptions implemented in my info-plist, I have tried deleting the app from my phone (I use my iPhone as a simulator) I have tried to reorganize my code, I have tried to comment out specific lines just to see if the message will go away and allow me to see my location. I have tried removing and reinstalling the google maps pods but nothing. I have tried to read up on this issue on StackOverflow, medium and GitHub to try and see if I can use previous tips to help solve my problem. I have even posted on here to see if I can get a little insight on this issue.
I have no idea what to do left to figure out this problem and I really don't want to start over. I will post the entirety of my code below, which is quite extensive. If someone has the free time to read through and let me know what I did wrong or did not implement, It would be greatly appreciated.
import UIKit
import GoogleMaps
import GooglePlaces
import CoreLocation
class mainViewController: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate, GMSAutocompleteViewControllerDelegate, UITextFieldDelegate {
let currentLocationMarker = GMSMarker()
var locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.navigationBar.prefersLargeTitles = false
navigationController?.navigationBar.titleTextAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white, NSAttributedStringKey.font: UIFont.systemFont(ofSize: 25)]
myMapView.delegate=self
locationManager.delegate = self
locationManager.requestWhenInUseAuthorization()
locationManager.requestAlwaysAuthorization()
locationManager.startMonitoringSignificantLocationChanges()
locationManager.startUpdatingLocation()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestAlwaysAuthorization()
setupViews()
initGoogleMaps()
txtFieldSearch.delegate=self
func initGoogleMaps() {
let camera = GMSCameraPosition.camera(withLatitude: 40.014281, longitude: -83.030914, zoom: 17.0)
self.myMapView.camera = camera
self.myMapView.delegate = self
self.myMapView.isMyLocationEnabled = true
}
func getLocation() {
let status = CLLocationManager.authorizationStatus()
if status == .notDetermined {
locationManager.requestWhenInUseAuthorization()
return
}
if status == .denied || status == .restricted {
let alert = UIAlertController(title: "Location Services Disabled", message: "Please enable Location Services in Settings", preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alert.addAction(okAction)
present(alert, animated: true, completion: nil)
return
}
}
@objc func btnMyLocationAction() {
let location: CLLocation? = myMapView.myLocation
if location != nil {
myMapView.animate(toLocation: (location?.coordinate)!)
}
}
let myMapView: GMSMapView = {
let v=GMSMapView()
v.translatesAutoresizingMaskIntoConstraints=false
return v
}()
let btnMyLocation: UIButton = {
let btn=UIButton()
btn.backgroundColor = UIColor.white
btn.setImage(#imageLiteral(resourceName: "my_location-1"), for: .normal)
btn.layer.cornerRadius = 25
btn.clipsToBounds=true
btn.tintColor = UIColor.gray
btn.imageView?.tintColor=UIColor.gray
btn.addTarget(self, action: #selector(btnMyLocationAction), for: .touchUpInside)
btn.translatesAutoresizingMaskIntoConstraints=false
return btn
}()
}
Go search the app target's build settings for "info.plist" and study the full path very carefully. Make sure you added the keys to the correct info.plist - that it's the one actually being used officially as the info.plist for your app build. You can also click on the Info tab next to Build Settings to verify the two entries are there.
Here's how it should look (only be sure to provide a value for BOTH of them):