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