Is it possible to reset authorizationStatus of CLLocationManager in macOS?

26 Views Asked by At

On macOS, is there a way to reset the authorizationStatus of the CLLocationManager back to kCLAuthorizationStatusNotDetermined (or .notDetermined in Swift)? Disabling the location permission for the app in System Settings only sets it to kCLAuthorizationStatusDenied (.denied) which is not the same thing. Only when not determined, calling requestAlwaysAuthorization has an effect, in all other cases this method has no effect on macOS (that's also how it is documented). But currently I can do that once on a development system and then never again. Even if I clear the Xcode build directory, the app will vanish from System Settings but the moment I re-build it, it's there before even starting it with the last status set, so I cannot re-test prompting the user for access.

1

There are 1 best solutions below

2
Mecki On

The comment from TheNextman pointed me into the right direction. Location permissions are indeed stored in /var/db/locationd/clients.plist. To edit this file, you must be root; actually you already must be root to view the file or enter its directory. But you also must kill locationd otherwise your edit has no effect. Here is a step by step guide:

  1. Open Terminal
  2. Become root: sudo su -
  3. Go to the directory: cd /var/db/locationd
  4. Find the identifier of your app: plutil -p cilents.plist. The identfier will be something like A436F23B-8069-4F67-B935-1DF9FE5F5903:icom.apple.iCal:
  5. Delete app entry:
    defaults delete `pwd`/clients.plist A436F23B-8069-4F67-B935-1DF9FE5F5903:icom.apple.iCal:
    
    (defaults will only work here with absolute path, hence the `pwd`/)
  6. Force locationd to restart: killall locationd

After those steps the status is back to kCLAuthorizationStatusNotDetermined (.notDetermined).