Ios 类型为的AVCaptureStillImageOutput连接返回nil连接
我正在使用Ios 类型为的AVCaptureStillImageOutput连接返回nil连接,ios,swift,ipad,Ios,Swift,Ipad,我正在使用AVCaptureStillImageOutput在iOS上拍摄照片。 要捕获照片,我将异步调用capturestillimage。 这需要连接,因此我使用: let connection=stillImageOutput.connection(withMediaType:AVMediaTypeVideo) 但是,在某些设备上,即iOS 9.3.5上的iPad 2上,我发现返回的连接为零 我还尝试使用以下方法遍历所有连接: stillImageOutput.connections 这表
AVCaptureStillImageOutput
在iOS上拍摄照片。
要捕获照片,我将异步调用capturestillimage
。
这需要连接,因此我使用:
let connection=stillImageOutput.connection(withMediaType:AVMediaTypeVideo)
但是,在某些设备上,即iOS 9.3.5上的iPad 2上,我发现返回的连接为零
我还尝试使用以下方法遍历所有连接:
stillImageOutput.connections
这表明没有可用的连接
还有其他人遇到过这个问题吗?是否有其他更好的方式获得连接?我意识到我使用的是一个不推荐的类,但是新方法在iOS 9上不可用,我们仍然需要支持这个平台。顺便说一句,相机应用程序本身似乎在这个设备上工作得很好
还注意到AVCaptureSession
上的canAddInput
返回false
输入如下所示:
guard let captureDevices = AVCaptureDevice.devices(withMediaType: AVMediaTypeVideo) as? [AVCaptureDevice],
let captureDevice = captureDevices.first(where: { $0.position == .back }),
let captureDeviceInput = try? AVCaptureDeviceInput(device: captureDevice) else {
return
}
在我的例子中,stillImageOutput.connections为nil,因为我分配了两次AVCaptureSession和AVCaptureVideoPreviewLayer,所以只添加了检查会话是否=nil,然后只执行[[AvCaptureSillImageOutput alloc]init]和所有stillImageOutput预设