App freezes after trying to use camera in iOS simu

2019-03-06 17:57发布

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?

1条回答
小情绪 Triste *
2楼-- · 2019-03-06 18:17

This is not a thrown exception. You must not use AVCaptureDeviceInput on the simulator at all.

Use #if arch(x86_64) to avoid having any code involving the camera even be present when compiling for the simulator.

查看更多
登录 后发表回答