无法获得AVCaptureDevice

问题描述 投票:0回答:1

还有另一个Mac Catalyst移植问题。在iOS上完美运行的用于获取视频的AVCaptureDevice的代码失败,并且在macOS上运行时返回nil。]

证明此问题的最简单方法是使用苹果公司自己的AvCam demo app。它在Swift和Objective-C中都提供。两者都以相同的方式失败。选中“ Mac”复选框,然后在Mac上构建并运行。授予摄像头权限,然后在控制台中发现错误。

在Swift版本中,查看CameraViewController的configureSession方法。行:

var defaultVideoDevice: AVCaptureDevice?

// Choose the back dual camera, if available, otherwise default to a wide angle camera.

if let dualCameraDevice = AVCaptureDevice.default(.builtInDualCamera, for: .video, position: .back) {
    defaultVideoDevice = dualCameraDevice
} else if let backCameraDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) {
    // If a rear dual camera is not available, default to the rear wide angle camera.
    defaultVideoDevice = backCameraDevice
} else if let frontCameraDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front) {
    // If the rear wide angle camera isn't available, default to the front wide angle camera.
    defaultVideoDevice = frontCameraDevice
}

即使已授予相机许可,也始终会显示nil

或查看Objective-C版本的AVCamCameraViewController类的configureSession方法。尝试获取AVCaptureDevice的相同代码失败。

我也尝试使用AVCaptureDevice default(for:)方法,并且我尝试使用AVCaptureDevice.DiscoverySession devices。在Mac上运行时,所有尝试都会失败,而在iOS设备上运行时,所有尝试都将失败。

使这一点更有趣的是,在与AvCam演示应用程序存在相同问题的我自己的应用程序中,我可以使用UIImagePickerController很好地拍照和捕获视频。这意味着,通常,Mac Catalyst应用程序可以使用Mac的相机拍摄照片和视频。

所以问题是,要获得用于视频的AVCaptureDevice,需要进行哪些更改?任何人都可以弄清楚AvCam演示应用程序在与Mac Catalyst一起运行时需要进行哪些更改吗?

还有另一个Mac Catalyst移植问题。在iOS上完美运行以获取用于视频目的的AVCaptureDevice的代码失败,并且在macOS上运行时返回nil。 ...

ios avcapturesession maccatalyst
1个回答
-1
投票

我遇到相同的问题,我的Xcode控制台显示“ [Generic]无法创建视频设备输入:错误域= AVFoundationErrorDomain代码= -11814”

© www.soinside.com 2019 - 2024. All rights reserved.