void ToggleLivePhotoMode(UIButton livePhotoModeButton)
        {
            sessionQueue.DispatchAsync(() =>
            {
                livePhotoMode      = (livePhotoMode == AVCamLivePhotoMode.On) ? AVCamLivePhotoMode.Off : AVCamLivePhotoMode.On;
                var lLivePhotoMode = livePhotoMode;

                //DispatchQueue.MainQueue.DispatchAsync(() =>
                //{
                //	if (lLivePhotoMode == AVCamLivePhotoMode.On)
                //	{
                //		LivePhotoModeButton.SetTitle(NSBundle.MainBundle.LocalizedString(@"Live Photo Mode: On", @"Live photo mode button on title"), UIControlState.Normal);
                //	}
                //	else
                //	{
                //		LivePhotoModeButton.SetTitle(NSBundle.MainBundle.LocalizedString(@"Live Photo Mode: Off", @"Live photo mode button off title"), UIControlState.Normal);
                //	}
                //});
            });
        }
        // Call this on the session queue.
        void ConfigureSession()
        {
            if (setupResult != AVCamSetupResult.Success)
            {
                return;
            }

            NSError error = null;

            session.BeginConfiguration();

            /*
             *      We do not create an AVCaptureMovieFileOutput when setting up the session because the
             *      AVCaptureMovieFileOutput does not support movie recording with AVCaptureSessionPresetPhoto.
             */
            session.SessionPreset = AVCaptureSession.PresetPhoto;

            // Add video input.

            // Choose the back dual camera if available, otherwise default to a wide angle camera.
            var videoDevice = AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInDualCamera, AVMediaType.Video, AVCaptureDevicePosition.Back);

            if (videoDevice == null)
            {
                // If the back dual camera is not available, default to the back wide angle camera.
                videoDevice = AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInWideAngleCamera, AVMediaType.Video, AVCaptureDevicePosition.Back);

                // In some cases where users break their phones, the back wide angle camera is not available. In this case, we should default to the front wide angle camera.
                if (videoDevice == null)
                {
                    videoDevice = AVCaptureDevice.GetDefaultDevice(AVCaptureDeviceType.BuiltInWideAngleCamera, AVMediaType.Video, AVCaptureDevicePosition.Front);
                }
            }
            var lVideoDeviceInput = AVCaptureDeviceInput.FromDevice(videoDevice, out error);

            if (lVideoDeviceInput == null)
            {
                Console.WriteLine($"Could not create video device input: {error}");
                setupResult = AVCamSetupResult.SessionConfigurationFailed;
                session.CommitConfiguration();
                return;
            }
            if (session.CanAddInput(lVideoDeviceInput))
            {
                session.AddInput(lVideoDeviceInput);
                videoDeviceInput = lVideoDeviceInput;

                DispatchQueue.MainQueue.DispatchAsync(() =>
                {
                    /*
                     *      Why are we dispatching this to the main queue?
                     *      Because AVCaptureVideoPreviewLayer is the backing layer for AVCamPreviewView and UIView
                     *      can only be manipulated on the main thread.
                     *      Note: As an exception to the above rule, it is not necessary to serialize video orientation changes
                     *      on the AVCaptureVideoPreviewLayer’s connection with other session manipulation.
                     *
                     *      Use the status bar orientation as the initial video orientation. Subsequent orientation changes are
                     *      handled by -[AVCamCameraViewController viewWillTransitionToSize:withTransitionCoordinator:].
                     */
                    var statusBarOrientation    = UIApplication.SharedApplication.StatusBarOrientation;
                    var initialVideoOrientation = AVCaptureVideoOrientation.Portrait;
                    if (statusBarOrientation != UIInterfaceOrientation.Unknown)
                    {
                        initialVideoOrientation = (AVCaptureVideoOrientation)statusBarOrientation;
                    }

                    VideoPreviewLayer.Connection.VideoOrientation = initialVideoOrientation;
                });
            }
            else
            {
                Console.WriteLine(@"Could not add video device input to the session");
                setupResult = AVCamSetupResult.SessionConfigurationFailed;
                session.CommitConfiguration();
                return;
            }

            // Add audio input.
            var audioDevice      = AVCaptureDevice.GetDefaultDevice(AVMediaType.Audio);
            var audioDeviceInput = AVCaptureDeviceInput.FromDevice(audioDevice, out error);

            if (audioDeviceInput == null)
            {
                Console.WriteLine($"Could not create audio device input: {error}");
            }
            if (session.CanAddInput(audioDeviceInput))
            {
                session.AddInput(audioDeviceInput);
            }
            else
            {
                Console.WriteLine(@"Could not add audio device input to the session");
            }

            // Add photo output.
            var lPhotoOutput = new AVCapturePhotoOutput();

            if (session.CanAddOutput(lPhotoOutput))
            {
                session.AddOutput(lPhotoOutput);
                photoOutput = lPhotoOutput;

                photoOutput.IsHighResolutionCaptureEnabled = true;
                photoOutput.IsLivePhotoCaptureEnabled      = photoOutput.IsLivePhotoCaptureSupported;
                //photoOutput.IsDepthDataDeliveryEnabled(photoOutput.IsDepthDataDeliverySupported());

                livePhotoMode = photoOutput.IsLivePhotoCaptureSupported ? AVCamLivePhotoMode.On : AVCamLivePhotoMode.Off;
                //depthDataDeliveryMode = photoOutput.IsDepthDataDeliverySupported() ? AVCamDepthDataDeliveryMode.On : AVCamDepthDataDeliveryMode.Off;

                inProgressPhotoCaptureDelegates  = new Dictionary <long, AVCamPhotoCaptureDelegate>();
                inProgressLivePhotoCapturesCount = 0;
            }
            else
            {
                Console.WriteLine(@"Could not add photo output to the session");
                setupResult = AVCamSetupResult.SessionConfigurationFailed;
                session.CommitConfiguration();
                return;
            }

            backgroundRecordingId = UIApplication.BackgroundTaskInvalid;

            session.CommitConfiguration();
        }