尝试在iOS模拟器中使用相机后,即使执行抓拍处理,应用也会冻结 [英] App freezes after trying to use camera in iOS simulator even with do catch handling
问题描述
我正在尝试将摄像头功能快速添加到我的应用程序3中.由于iOS模拟器没有摄像头,因此我编写了一个do catch,以使该应用程序无法在模拟器中使用摄像头后继续运行.>
I am trying to add camera functionality to my app in swift 3. Since the iOS simulator has no camera, I wrote a do catch to allow the app to continue running after it fails to use the camera in the simulator.
do{
let captureDeviceInput = try AVCaptureDeviceInput(device: captureDevice)
captureSession.addInput(captureDeviceInput)
}catch{
print("there was an error adding camera as input: ")
print(error.localizedDescription)
}
返回的错误是无法记录".但是,这只会完全冻结该应用程序.我在错误处理中是否缺少某些东西,或者这是使用模拟器不可避免的副作用?
the error returned is "Cannot Record". However, this just freezes the app completely. Am I missing something in my error handling or is this an unavoidable side effect of using simulator?
推荐答案
这不是引发的异常.您完全不能在模拟器 上使用AVCaptureDeviceInput.
This is not a thrown exception. You must not use AVCaptureDeviceInput on the simulator at all.
使用#if arch(x86_64)
可以避免在为模拟器进行编译时甚至出现与摄像机有关的任何代码.
Use #if arch(x86_64)
to avoid having any code involving the camera even be present when compiling for the simulator.
这篇关于尝试在iOS模拟器中使用相机后,即使执行抓拍处理,应用也会冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!