【问题标题】:How do I fix the error "deviceInputWithDevice is unavailable"?如何修复错误“deviceInputWithDevice 不可用”?
【发布时间】:2015-06-20 00:43:28
【问题描述】:

我正在将我的应用程序从 Swift 升级到 Swift 2 并遇到以下错误: 'deviceInputWithDevice' is unavailable: use object construction 'AVCaptureDeviceInput(device:error:)'

这里是有问题的代码:

    let captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
    var input:AVCaptureDeviceInput
    let error:NSError?

    do {
        let input = try AVCaptureDeviceInput.deviceInputWithDevice(captureDevice) as AVCaptureDeviceInput
    } catch let error as NSError {
        print(error)
    }

有人可以帮我理解建议的解决方案:“使用对象构造'AVCaptureDeviceInput(device:error:)'”以及如何实现它吗?

【问题讨论】:

    标签: swift swift2


    【解决方案1】:
        do {
            let input = try AVCaptureDeviceInput(device: captureDevice) as AVCaptureDeviceInput
            // moved the rest of the image capture into the do{} scope.
    

    【讨论】:

    • 找到它catch let error as NSError { println(error) }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-28
    • 2019-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多