swift - 类型 'AVCaptureDevice' 没有成员 'defaultDevice'

标签 swift avcapturedevice

正在研究二维码阅读器。我是编程新手,所以这可能很容易解决。错误是“类型‘AVCaptureDevice’没有成员‘defaultDevice’”提前感谢您的帮助!

 //Creating session
    let session = AVCaptureSession()
    //Define capture device
    let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)

    do
    {
        let input = try AVCaptureDeviceInput(device: captureDevice)
        session.addInput(input)
    }

最佳答案

您正在使用旧的 Swift 2 API。线路:

let captureDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)

应该是:

let captureDevice = AVCaptureDevice.default(for: .video)

关于swift - 类型 'AVCaptureDevice' 没有成员 'defaultDevice',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46945104/

相关文章:

ios - 如何组合两个可选的数组

ios - AVCaptureSession 和背景音频 iOS 7

iphone - 为什么 AVCaptureSession 输出错误的方向?

ios - 将前置摄像头与 AVFoundation 一起使用时,闪光灯不起作用

ios - UICollectionViewCell 中托管的 UITableViewController 的滚动问题

ios - XCode 6 中的滑动手势 StoryBoard 对象不起作用

ios - 无法将类型 'x' 的值转换为预期的参数类型 '[String : Any]'

ios - 使用自定义相机快门声音

ios - AVCaptureVideoPreviewLayer(相机预览)在移动到背景和返回后卡住/卡住

ios - 如何设置 UIContextualAction 的圆角半径?