AVCam Project Crashes On iPad

Add this ...

let position = self.videoDeviceInput.device.position
photoSettings.flashMode = position == .front || position == .unspecified ? .off : .auto

right before this ...

self.photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate)

That should fix the problem.


// Also for someone that might be having this problem while trying to use the Apple supplied AVCam sample code in XCode on MacOS, using the Objective C supplied version of the code, just add this (in Objective C):

AVCaptureDevicePosition position = self.videoDeviceInput.device.position;
if (position == AVCaptureDevicePositionFront)
{
   photoSettings.flashMode = AVCaptureFlashModeOff;
}
else
{
   photoSettings.flashMode = AVCaptureFlashModeAuto;
}


//right before:

[self.photoOutput.capturePhoto(with: photoSettings, delegate: photoCaptureDelegate]