From cb0a87f03bde22f692c919a0a4333cc9d95892ba Mon Sep 17 00:00:00 2001 From: Kevin Kieffer Date: Wed, 13 Nov 2019 11:57:54 -0500 Subject: [PATCH] Fix issue #3, nil device causes crash when running on simulator. Now, error is printed. --- ALCameraViewController/Views/CameraView.swift | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ALCameraViewController/Views/CameraView.swift b/ALCameraViewController/Views/CameraView.swift index 771d378c..5fde91a2 100644 --- a/ALCameraViewController/Views/CameraView.swift +++ b/ALCameraViewController/Views/CameraView.swift @@ -28,7 +28,12 @@ public class CameraView: UIView { session.sessionPreset = AVCaptureSession.Preset.photo device = cameraWithPosition(position: currentPosition) - if let device = device , device.hasFlash { + if device == nil { + print("Error: No Camera device found") + return + } + + if device.hasFlash { do { try device.lockForConfiguration() device.flashMode = .auto