Checking authorization status of AVCaptureDevice or CLLocation Manager gives runtime warnings in iOS 18

I have the following code in my ObservableObject class and recently XCode started giving purple coloured runtime issues with it (probably in iOS 18):

 Issue 1: Performing I/O on the main thread can cause slow launches.  

 Issue 2: Interprocess communication on the main thread can cause non-deterministic delays.

Issue 3: Interprocess communication on the main thread can cause non-deterministic delays.

Here is the code:

@Published var cameraAuthorization:AVAuthorizationStatus
@Published var micAuthorization:AVAuthorizationStatus
@Published var photoLibAuthorization:PHAuthorizationStatus
@Published var locationAuthorization:CLAuthorizationStatus

var locationManager:CLLocationManager

override init() {

    // Issue 1 (Performing I/O on the main thread can cause slow launches.)
    
    cameraAuthorization = AVCaptureDevice.authorizationStatus(for: AVMediaType.video) 


    micAuthorization = AVCaptureDevice.authorizationStatus(for: AVMediaType.audio)
    photoLibAuthorization = PHPhotoLibrary.authorizationStatus(for: .addOnly)

 //Issue 1: Performing I/O on the main thread can cause slow launches.
    locationManager = CLLocationManager()
    
    locationAuthorization = locationManager.authorizationStatus
    
    super.init()
    
  //Issue 2: Interprocess communication on the main thread can cause non-deterministic delays.
    locationManager.delegate = self
}

And also in route Change notification handler of AVAudioSession.routeChangeNotification,

 //Issue 3: Hangs -  Interprocess communication on the main thread can cause non-deterministic delays.

    let categoryPlayback = (AVAudioSession.sharedInstance().category == .playback)

I wonder how checking authorisation status can give these issues? What is the fix here?

These warnings are indeed real. And whether these are "possible" issues you can live with

As they explain, checking the authorization status requires either reading the status from a location (I/O) or ask an OS component whether the app is currently authorized (Interprocess Communication). These need to be checked live, as the user can, at any time, revoke the authorization they have given to an app.

If you do not want the warnings and/or the side effects you may have observed, like it says, you should move these checks to a background thread.


Argun Tekant /  DTS Engineer / Core Technologies

Checking authorization status of AVCaptureDevice or CLLocation Manager gives runtime warnings in iOS 18
 
 
Q