swift - 如何修复错误 "deviceInputWithDevice is unavailable"?

标签 swift swift2

我正在将我的应用程序从 Swift“升级”到 Swift 2 并遇到以下错误: 'deviceInputWithDevice' 不可用:使用对象构造 '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:)’”以及如何实现它吗?

最佳答案

    do {
        let input = try AVCaptureDeviceInput(device: captureDevice) as AVCaptureDeviceInput
        // moved the rest of the image capture into the do{} scope.

关于swift - 如何修复错误 "deviceInputWithDevice is unavailable"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30949154/

相关文章:

ios - 在 iPhone 5 和 iPhone SE 中获取空设备 token

ios - 如何在应用程序终止或终止时点击推送通知后打开特定 Controller

ios - 如何为自定义 UIButton 的不同状态使用矢量图形?

ios - 如何根据 dp(不是点数)在 iOS 中设置 UILabel 字体大小,就像只有自动布局的 android 一样

ios - 不同维度的单个 CollectionView 中的两个单元格

objective-c - Xcode 6 Swift 部分自动完成方法

ios - 经过身份验证的 http 请求 swift Alamofire

iphone - 如何在 UITableView 之上添加一个 UIImage

ios - iOS 堆栈 View 中水平居中 View

ios - 我如何在字符串支持的枚举数组上使用字符串函数?