可以将 AVCaptureFileOutputRecordingDelegate 添加到子类 UIView 吗?

Can a AVCaptureFileOutputRecordingDelegate be added to a subclass UIView?

我在自定义 UIView 中创建捕获会话时遇到问题。我这样设置委托

class Camera: UIView, AVCaptureFileOutputRecordingDelegate, AVAudioRecorderDelegate {
}

然后我设置好所有内容并像这样设置委托

self.recordingDelegate? = self

    captureSession.sessionPreset = AVCaptureSessionPresetHigh
    let devices = AVCaptureDevice.devices()
    for device in devices {
        if (device.hasMediaType(AVMediaTypeVideo)) {
            if(device.position == AVCaptureDevicePosition.Back) {
                captureDevice = device as? AVCaptureDevice
                if captureDevice != nil {
                    beginSession()
                }
            }
        }
    }

一切顺利。但是,在 beginSession 函数中:

    func beginSession() {
        let err : NSError? = nil
        do {
            self.captureSession.addInput(try AVCaptureDeviceInput(device: self.captureDevice!))
        }
        catch {
            print("dang")
        }
        if err != nil {
            print("error: \(err?.localizedDescription)")
        }

...

当我尝试添加捕获设备输入时抛出问题,但没有添加,我不明白为什么。

我目前使用的所有代码在我将它放入 UIViewController 之前都工作正常,但是当我将它切换到 UIView 的子类时它停止工作。如果需要更多代码,请告诉我,谢谢!

我发现我使用的 iOS 设备由于某种原因没有启用摄像头,无法添加输入导致预览层无法捕获任何数据