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?
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.