类型AVCaptureDevice不符合协议序列

时间:2018-05-29 15:15:04

标签: swift firebase

我正在尝试打开前置摄像头以便进行自拍并将其保存为输出,以便用户在提交之前能够看到图片。我配置的原始功能在iOS 10下折旧。 有人可以帮助理解如何正确地写这个吗?

http://example.com/controller/phpinfo

1 个答案:

答案 0 :(得分:0)

查看documentation

class func `default`(_ deviceType: AVCaptureDevice.DeviceType, 
                 for mediaType: AVMediaType?, 
            position: AVCaptureDevice.Position) -> AVCaptureDevice?

因此default方法返回一个可选的AVCaptureDevice

您只需要替换

//NEW CODE:   
   let devices = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front)
     )

    for device in devices {
        if device.position == AVCaptureDevice.Position.front {

//NEW CODE:   
        if let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front) {