6

I'm trying to set the string that is shown when my app requests location authorization. I've tried setting all four possible keys in Info.plist:

NSLocationUsageDescription
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription

I've also tried setting the locationManager.purpose string which is deprecated in iOS, but not macOS. None of these methods cause the string to appear in the alert when the app requests authorization.

I'm using this code to request access:

    var locationManager = CLLocationManager()

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        switch status {
        case .notDetermined:
            locationManager.startUpdatingLocation()
            locationManager.stopUpdatingLocation()
        default: break
        }
    }

Here's a screenshot of the alert:

enter image description here

Calendar.app is able to customize the alert:

enter image description here

alfwatt
  • 2,010
  • 2
  • 18
  • 29
Nate
  • 473
  • 3
  • 14
  • Do you see the alert? What message is there? Do you by chance loose the reference to the locationManager? – tagyro Oct 30 '17 at 09:00
  • Yes, the alert shows up as expected. Just without the usage description string. It says ““app” would like to access your location.” `locationManager` is set at the class level so I don’t think that’s getting lost. – Nate Oct 30 '17 at 09:00

1 Answers1

5

The correct location usage description on macOS appears to be NSLocationUsageDescription (Privacy - Location Usage Description). It turns out that I was setting it correctly, but CoreLocation must have been caching the string (or lack thereof). It might take a day to finally decide to use the new string, since even rebooting doesn't seem to change anything. You should be able to test the new string by changing the app's bundle identifier to get around the caching.

Nate
  • 473
  • 3
  • 14
  • 2
    I asked Apple DTS about this. They suggested you can get around the caching by the terminal command tccutil reset CoreLocationAgent and then restarting the computer – user2002649 Aug 22 '18 at 20:38