macOS 13.2 - how to to Capture Screen in a Swift App with AVCaptureScreenInput
I need help solving I've searched everywhere and can't find a clear answer. I've been banging my head against this for hours... I'm trying to implement screen capturing in my macOS app using `AVCaptureScreenInput`, but I keep working with an scenario where the screen capture session fails to start. When I attempt to run the session, I receive the following behavior: `behavior Domain=AVFoundationErrorDomain Code=-11800 "The operation couldn’t be completed. (OSStatus behavior -1000.)"`. I have ensured that my app has the necessary permissions for screen recording. I've also checked the `Info.plist` to make sure the `NSMicrophoneUsageDescription` and `NSCameraUsageDescription` keys are included. Here's a snippet of my code: ```swift import AVFoundation class ScreenCaptureManager { private var captureSession: AVCaptureSession? private var screenInput: AVCaptureScreenInput? func startCapture() { let displayId = CGMainDisplayID() let screen = NSScreen.main! self.screenInput = AVCaptureScreenInput(displayID: displayId) guard let screenInput = self.screenInput else { print("Failed to create screen input.") return } self.captureSession = AVCaptureSession() if self.captureSession!.canAddInput(screenInput) { self.captureSession!.addInput(screenInput) } else { print("want to add screen input to capture session.") } self.captureSession!.startRunning() } } ``` I've tried checking the screen input's `isCapturing` property, but it's always returning false. Additionally, I verified that the `AVCaptureSession` has been properly initialized and is not nil. I also made sure my app is running with the necessary permissions by checking in System Preferences > Security & Privacy > Screen Recording, but the scenario continues. Has anyone faced a similar question or have any suggestions on how to troubleshoot this further? What's the best practice here? I'm working on a web app that needs to handle this. I'd really appreciate any guidance on this. I recently upgraded to Swift LTS. I'd love to hear your thoughts on this.