From 9bd7af396c62f3862f6eb8ec615d665134737005 Mon Sep 17 00:00:00 2001 From: Michael Wolz Date: Wed, 26 Jun 2024 21:58:38 +0200 Subject: [PATCH] fix(ios): check focus / exposure mode support --- ios/Plugin/CameraController.swift | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ios/Plugin/CameraController.swift b/ios/Plugin/CameraController.swift index 3070888..eef7874 100644 --- a/ios/Plugin/CameraController.swift +++ b/ios/Plugin/CameraController.swift @@ -90,8 +90,15 @@ class CameraController: NSObject { do { try self.currentCamera?.lockForConfiguration() self.currentCamera?.videoZoomFactor = self.zoomFactor - self.currentCamera?.exposureMode = .continuousAutoExposure - self.currentCamera?.focusMode = .continuousAutoFocus + + if (self.currentCamera?.isFocusModeSupported(.continuousAutoFocus) ?? false) { + self.currentCamera?.focusMode = .continuousAutoFocus + } + + if (self.currentCamera?.isExposureModeSupported(.continuousAutoExposure) ?? false) { + self.currentCamera?.exposureMode = .continuousAutoExposure + } + self.currentCamera?.unlockForConfiguration() completionHandler(nil) @@ -116,6 +123,8 @@ class CameraController: NSObject { */ private func initializeCameraDevices(forPosition cameraPosition: CameraPosition) throws { if let rearCamera = AVCaptureDevice.default(.builtInTripleCamera, for: .video, position: .back) { + // Note that zoomFactor 2 "equals" the regular 1x zoom factor of the native iphone camera app + // 0.5x is videoZoomFactor 1. We do not want to use ultra wide angle by default so we set it to 2 self.zoomFactor = 2 self.rearCamera = rearCamera } else {