Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

locationManager:didChangeAuthorization vs locationManagerDidChangeAuthorization

In an iOS app using SwiftUI and CoreLocation. I need to keep an eye on the status of the permissions given by the user for location access.

Looking at the documentation for CLLocationManagerDelegate, it looks like I am supposed to use the locationManagerDidChangeAuthorization method.

The problem is this method never gets called (as far as I can see). Beside, the other method locationManager:didChangeAuthorization (supposed to be deprecated) seems to do the job.

If someone has any good advice, please let me know.

like image 754
Michel Avatar asked Jul 08 '20 02:07

Michel


1 Answers

locationManagerDidChangeAuthorization is only available in iOS 14. If you are running an earlier version of iOS you will need to use the older method, locationManager:didChangeAuthorization. Although it is deprecated, it still works (and you must use it if you are supporting earlier iOS versions).

The reason for the delegate method change is covered in a WWDC 2020 session - In iOS 14 location permission has a time permission (never/when in use/always) and a new precision permission (high/low precision).

The original delegate method delivers the time permission to the delegate method, but doesn't deliver the precision information (since that permission didn't exist previously).

Rather than create a new delegate method that receives both the time and precision permission details, Apple have opted for a simple method that tells you something has changed. You then need to write code to check the CLLocationManager to determine the permissions you have and what to do about it.

Why they did it this way, we can only speculate, but I suspect that it gives them flexibility to add further permissions in the future without changing the method signature.

like image 112
Paulw11 Avatar answered Nov 15 '22 12:11

Paulw11