How to get the AVCam demo app to work under Mac Catalyst?

My own iOS app is using AVFoundation to do barcode scanning. Under Mac Catalyst I'm getting an error. Turns out the Apple provided AVCam demo app has the exact same issue.


Both the Swift and Objective-C versions of the AVCam demo app fail but the Objective-C version gives a better error so I'll refer to that in the rest of the question.


In the AVCamCameraViewController, the configureSession method fails on the line:


AVCaptureDeviceInput* videoDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoDevice error:&error];


The error is:


Could not create video device input: Error Domain=AVFoundationErrorDomain Code=-11814 "Cannot Record" UserInfo={NSLocalizedDescription=Cannot Record, NSLocalizedRecoverySuggestion=Try recording again.}


It turns out that none of the three attempts to call [AVCaptureDevice defaultDeviceWithDeviceType:... are succeeding.


This is the same error I get in my own app though I only attempt to call [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; which is also returning nil.


Permission was granted for the app to access the camera.


There is nothing related to this issue in the release notes for macOS 10.15. I am running the GM version of 10.15 with Xcode 11.1 on a 2018 15" Macbook Pro.


How do we successfully get a video capture device under Mac Catalyst?

Answered by RCPPzaken in 389519022

I received an answer from Apple after submitting a feedback ticket about this:
This issue behaves as intended.
We do document that we are not listing devices in Catalyst mode.
See
Important iPad apps running in macOS cannot use the AVFoundation Capture classes. These apps should instead use UIImagePickerController for photo and video capture.


Please close your feedback report, or let us know if this is still an issue for you.
https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture
So unless they update it in the future it's not possible to access the camera on a Mac from a Catalyst app.

Rick:


I presume you've added the NSCameraUsageDescription | $(PRODUCT_NAME) key to Info.plist.


AKA Privacy - Camera Usage Description


When I build and run AVCam on my mac mini w/USB camera (Xcode 11.1/Swift/Catalyst), it succeeds/no errors, but then complains about not being able to access the default camera via an alert stating "Unable to capture media". I do not see a request to use dialog.


I'll play with it for while...


ken

Accepted Answer

I received an answer from Apple after submitting a feedback ticket about this:
This issue behaves as intended.
We do document that we are not listing devices in Catalyst mode.
See
Important iPad apps running in macOS cannot use the AVFoundation Capture classes. These apps should instead use UIImagePickerController for photo and video capture.


Please close your feedback report, or let us know if this is still an issue for you.
https://developer.apple.com/documentation/avfoundation/cameras_and_media_capture
So unless they update it in the future it's not possible to access the camera on a Mac from a Catalyst app.

This is terrible. I can't scan barcodes using UIImagePickerController.

>> Important

iPad apps running in macOS cannot use the AVFoundation Capture classes. These apps should instead use UIImagePickerController for photo and video capture. <<


REALLY?!


AVFoundation works in normal mac apps.

AVFoundation works in normal iOS apps.

but it doesn't work in maccatalyst?


is this a current limitation that is going to be addressed soon or what?

can i somehow compile, say, a separate macOS library and use it in maccatalyst app to overcome this limitation?


in our case that is a show stopper... we do a skype type messanger. i do not think it is realistic (or sane) to rebase our AV camera code on UIImagePickerController... the app is otherwise ok on mac (we were actually surprised by the speed of bringing it to mac, and overall quality was acceptable, so quality / time ratio was awesome), but inability to do video calls is definitely a dead end for us... our options:


- maccatalyst (but no video calls) 😟

- a separate mac app using swiftUI (and later backport it to iOS when time allows). it feels raw at the moment but we shall give it a try 😕

- a separate mac app using traditional Cocoa


sad

Overdue update - The AVCam demo now runs under Mac Catalyst. Much of AVFoundation has been supported since Mac Catalyst 14.0. The AVCam demo needs a few small changes to build for Mac Catalyst. By default, the project is not setup with a Mac Catalyst destination. It only supports iPad apps running on Apple Silicon. Delete the "Mac (Designed for iPad)" destination and add the "Mac (Mac Catalyst)" destination. You may also have to change the macOS Deployment target in the Build Settings depending on the version of macOS running on your Mac.

Thanks Apple for adding support for AVFoundation.

Now I just need to figure out if I can support Camera Continuity under Mac Catalyst.

How to get the AVCam demo app to work under Mac Catalyst?
 
 
Q