Xcode 14.1 Main thread warning with CLLocationManager.locationServicesEnabled()

Greetings to all.

After upgrading to Xcode 14.1 my app that is on deployment target iOS 13 and above gets the warning :

This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the -locationManagerDidChangeAuthorization: callback and checking authorizationStatus first

After reading some answers in StackOverflow it is suggested to wrap it in DispatchQueue.global however due to the complexity of my app and my current use case I cannot use it in this manor.

The warning only appears in the latest Xcode 14.1 in Xcode 13.XX the warning does not appear.

Is there any way to silence the warning without wrapping it in a DispatchQueue or using the delegate method?

Thanks for the help.

The better choice here is to embrace what the error says, and restructure your code that checks the authorization status property to instead wait until you are informed of the current authorization through your CLLocationManagerDelegate. The API documentation has information on when the delegate method is called:

Check this value when the locationManagerDidChangeAuthorization(_:) delegate callback indicates that the authorization status has changed. The system is guaranteed to call the delegate method with the app’s initial authorization state and all authorization status changes.

First of all thanks for the quick response.

2nd of all in our app current work flow and configuration I can't really use the delegate method.

Is there any way to use it like previously and just get the bool value if the location services are enabled in the device?

Thanks for the help.

Xcode 14.1 Main thread warning with CLLocationManager.locationServicesEnabled()
 
 
Q