3

I get this error:

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

Before iOS 16 UI was fine, now it indeed seems laggy.

Apparently it is linked to AdMob. Google says it is a bug with Apple. https://developer.apple.com/forums/thread/714467

Worst part is that in testing I actually think it does cause UI Unresponsiveness. I really don't think waiting for an update is a good solution.

Have any of you had this and done something to fix it?

This is how my code looks:

if CLLocationManager.locationServicesEnabled() {
    let authorizationStatus: CLAuthorizationStatus
    if #available(iOS 14, *) {
        authorizationStatus = locationManager.authorizationStatus
    } else {
        authorizationStatus = CLLocationManager.authorizationStatus()
    }

    switch authorizationStatus {
    case .authorizedAlways, .authorizedWhenInUse:
    case .notDetermined:
    case .restricted:
    case .denied:
    @unknown default:
        print("Location services are not enabled")
    }
greybeard
  • 2,249
  • 8
  • 30
  • 66
florida27
  • 67
  • 1
  • 7
  • What is the connection between Google and [the post hyperlinked](https://developer.apple.com/forums/thread/714467)? – greybeard Jul 17 '23 at 07:30

1 Answers1

0

The warning is showing because you are calling the CLLocationManager.locationServicesEnabled() in the main thread, you are already checking with locationManager.authorizationStatus if the location services are enabled, if you need to perform some action with the location services enabled you can do it in the case .authorizedAlways, .authorizedWhenInUse:

     let authorizationStatus: CLAuthorizationStatus
    if #available(iOS 14, *) {
        authorizationStatus = locationManager.authorizationStatus
    } else {
        authorizationStatus = CLLocationManager.authorizationStatus()
    }

    switch authorizationStatus {
    case .authorizedAlways, .authorizedWhenInUse:
    // your code here
    case .notDetermined:
    case .restricted:
    case .denied:
    @unknown default:
        print("Location services are not enabled")
zacdejesus
  • 26
  • 6