gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 05:29:55 26 4
gpt4 key购买 nike

我正在将我的应用程序从 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com