I am looking into a piece of old code where the mentioned method is called.
+ (bool)isLocationServicesEnabled {
return [CLLocationManager locationServicesEnabled];
}
I'm getting the classic "This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization:
callback and checking authorizationStatus
first."
I have 2 questions:
-
What is that error about, really? The locationServicesEnabled() has nothing to do with authorisation, it's just about the "location services" settings global on-off switch? (the authorisation check is .authorizationStatus)
-
I don't understand why that call is such a big issue? It's just a setting? Why would that be so costly?
Thankful for pointers! Have a good one
locationServicesEnabled()
has everything to do with authorization. If the user disables this setting, your app will not able to receive authorization, and if it has been authorized before, it will lose that authorization.
You only need to check this if your app cares and can do something about why it does not have authorization. You can always just check .authorizationStatus
and decide on your next steps if it is not important to know 'why'.
It may seem like "just a setting", but it is a synchronous call that needs to go out of your process to check that setting, and that is not an atomic action. Meaning, your main thread will block while it is waiting for a response. Whether it is a big issue or not depends on your app. It may matter to you if you are playing video, streaming real time data, or gaming. Or you may not care if your app mostly sits idle at your UI. Hence it's a warning you may heed or ignore.
Argun Tekant / DTS Engineer / Core Technologies