尝试在iOS模拟器中使用相机后,应用程序冻结,即使执行捕获处理

我正在尝试在swift 3中将相机function添加到我的应用程序中。由于iOS模拟器没有相机,因此我写了一个do catch以允许应用程序在模拟器中使用相机失败后继续运行。

do{ let captureDeviceInput = try AVCaptureDeviceInput(device: captureDevice) captureSession.addInput(captureDeviceInput) }catch{ print("there was an error adding camera as input: ") print(error.localizedDescription) } 

返回的错误是“不能logging”。 但是,这完全冻结了应用程序。 我错过了我的error handling的东西,或者这是使用模拟器不可避免的副作用?

这不是一个抛出的exception。 根本不能在模拟器使用AVCaptureDeviceInput。

使用#if arch(x86_64)可避免在编译模拟器时涉及摄像头的任何代码。