Я пытаюсь захватить видеокадры камеры с помощью AVCaptureSession в быстрой версии 3. После предоставления разрешения камеры canAddInput возвращает мне ложное значение.Я не вижу, что здесь не так.По каким причинам функция canAddInput может возвращать ложное значение?
private var position = AVCaptureDevicePosition.front
func configureSession() -> Bool? {
var captureSession = AVCaptureSession()
captureSession.sessionPreset = AVCaptureSessionPresetLow
let cameraString = "back"
switch cameraString {
case "back":
position = AVCaptureDevicePosition.back
default:
position = AVCaptureDevicePosition.front
}
let camera = selectCaptureDevice()
guard let captureDeviceInput = try? AVCaptureDeviceInput(device: camera) else { errback(str: "Input couldnt be created"); return false }
if !captureSession.canAddInput(captureDeviceInput) {
NSLog("Input cant be added. First attempt")
}
}
private func selectCaptureDevice() -> AVCaptureDevice? {
return AVCaptureDevice.devices().filter {
($0 as AnyObject).hasMediaType(AVMediaTypeVideo) &&
($0 as AnyObject).position == position
}.first as? AVCaptureDevice
}