1

I know my Macbook's webcam has a wide field of view. When I open the Quicktime app and select my MacBooks camera as the input I see a nice wide video feed like this.

enter image description here

Now, I have an iOS app which I'm running using Mac Catalyst. Here is the build combination I am using.

enter image description here

When I run this app I get a significantly cropped version of the video feed from the web cam.

enter image description here

Here is the class where I set up the AVCaptureSession

import Foundation
import AVFoundation


class BasicCamera: ObservableObject {
    
    @Published var authorizationState: AVAuthorizationStatus = .notDetermined
    
    let session = AVCaptureSession()
    
    init() {
        guard let device = AVCaptureDevice.default(for: .video) else {
            fatalError("Could not make capture device.")
        }
        
        guard let input = try? AVCaptureDeviceInput(device: device) else {
            fatalError("Could not make input")
        }
        
        session.beginConfiguration()
        
        session.addInput(input)
        
        session.commitConfiguration()
        
        session.startRunning()
    }
    
    public func requestCameraPermission() async -> AVAuthorizationStatus {
        return await withCheckedContinuation({ continuation in
            AVCaptureDevice.requestAccess(for: .video) { [unowned self] didComplete in
                self.authorizationState = AVCaptureDevice.authorizationStatus(for: .video)
                continuation.resume(with: .success(self.authorizationState))
            }
        })
    }
    
}

And add it to the ViewController like this:

let preview = AVCaptureVideoPreviewLayer(session: session)
preview.removeFromSuperlayer()  
preview.frame = self.view.bounds      
self.view.layer.insertSublayer(preview, at: 0)

Note that the UIViewController I'm using is brought into SwiftUI via UIViewControllerRepresentable protocol conformance.

I have tried a number of presets and discovery sessions parameters including .buildInWidtAngleCamera but can't seem to get it to show the full camera resolution? Am I out of luck here unless I build it as an actual native Mac Application?

lorem ipsum
  • 21,175
  • 5
  • 24
  • 48
Jon Vogel
  • 5,244
  • 1
  • 39
  • 54
  • 1
    Have you tried using `Optimize interface for Mac`? it is un her Target>General>Deployment Info>Next To the Mac checkmark button. Just a guess since it is likely identifying the camera as portrait for the iapd – lorem ipsum Nov 22 '21 at 23:41
  • Nice! You are very correct. – Jon Vogel Nov 23 '21 at 00:10

1 Answers1

2

Switch to Optimize interface for Mac it is under Target>General>Deployment Info>Next To the Mac checkmark button.

It is likely identifying the camera as portrait for the iPad

lorem ipsum
  • 21,175
  • 5
  • 24
  • 48