Deepak Sharma
Deepak Sharma

Reputation: 6581

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.

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
}

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

Upvotes: 2

Views: 150

Answers (0)

Related Questions