import UIKit
import AVKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//start camera
let captureSession = AVCaptureSession()
guard let captureDevice =
AVCaptureDevice.default(for: .video) else { return }
guard let input = try? AVCaptureDeviceInput(device:
captureDevice ) else { return }
captureSession.addInput(input)
captureSession.startRunning()
}
}
我收到此行中的错误(对于: .video ):
AVCaptureDevice.default(for: .video) else { return }
答案 0 :(得分:5)
用AVMediaTypeVideo替换AVMediaType.video对我有用。
答案 1 :(得分:0)
方法
class func `default`(_ deviceType: AVCaptureDevice.DeviceType,
for mediaType: AVMediaType?,
position: AVCaptureDevice.Position) -> AVCaptureDevice?
接受DeviceType,可以是:
AVCaptureDeviceTypeBuiltInMicrophone
AVCaptureDeviceTypeBuiltInWideAngleCamera
AVCaptureDeviceTypeBuiltInTelephotoCamera
AVCaptureDeviceTypeBuiltInDualCamera
AVCaptureDeviceTypeBuiltInDuoCamera
答案 2 :(得分:0)
我想我已经弄明白了。我正在查看的文档是针对Xcode 9.您需要的是首先导入AVFoundation
然后使用此函数:
class func defaultDevice(withDeviceType deviceType: AVCaptureDeviceType!,
mediaType: String!,
position: AVCaptureDevicePosition) -> AVCaptureDevice!
例如:
let c = AVCaptureDevice.defaultDevice(withDeviceType: AVCaptureDeviceType.builtInTelephotCamer,
mediaType: AVMediaTypeVideo,
position: AVCaptureDevicePosition.front)
答案 3 :(得分:0)
我只是想将我的项目转换为Swift4。这对我有用。
{{1}}
答案 4 :(得分:0)
在将“ Swift语言版本”设置为“ Swift 3.3”时,我遇到了这个确切的错误。
将快速语言版本从“ 3.3”更改为“ 4.1”为我解决了这个问题。