Lim Thye Chean
Lim Thye Chean

Reputation: 9434

Using camera with Mac Catalyst

In an app ported to Mac Catalyst, the camera interface always turned out to be blank.

I have checked: the capabilities includes "Camera", the privacy setting in info.plist is there (the iPad app shows the camera fine), and I even try to include front camera for UIImagePickerController.

    if UIImagePickerController.isSourceTypeAvailable(.camera) {
        let imagePicker = UIImagePickerController()
        imagePicker.sourceType = .camera
        imagePicker.delegate = self
        imagePicker.cameraDevice = .front   // added for Mac
        self.present(imagePicker, animated:true, completion:nil)            
    }

The error I got is: "[Generic] Could not create video device input: Error Domain=AVFoundationErrorDomain Code=-11814"

Upvotes: 0

Views: 877

Answers (2)

Carlos Chaguendo
Carlos Chaguendo

Reputation: 3085

You need Requesting Authorization for Media Capture on macOS

import AVFoundation

AVCaptureDevice.requestAccess(for: .video) { granted in
     let ctrl = UIImagePickerController()
     ctrl.sourceType = .camera
     self.present(ctrl, animated: true, completion: nil)
}

Add to info.plist

<key>NSCameraUsageDescription</key>
<string>  .... </string>

Upvotes: 0

Ragazzetto
Ragazzetto

Reputation: 642

I have the same mistake, I'm afraid it's a bug ... Everything works correctly on iOS and iPadOS. For the moment I think there's no way to make it work...

Upvotes: 0

Related Questions