From 62ca95725de0bf1cda4e9301780e83f6653aad95 Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Fri, 13 Oct 2023 18:44:44 +0200 Subject: [PATCH] fix: Fix torch not turning off after it has been enabled (#1997) fix: Fix torch and low-light boost not turning off again --- .../ios/Core/CameraSession+Configuration.swift | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/package/ios/Core/CameraSession+Configuration.swift b/package/ios/Core/CameraSession+Configuration.swift index deb3d83..eb02b9f 100644 --- a/package/ios/Core/CameraSession+Configuration.swift +++ b/package/ios/Core/CameraSession+Configuration.swift @@ -226,22 +226,23 @@ extension CameraSession { } // Configure Low-Light-Boost - if configuration.enableLowLightBoost { - let isDifferent = configuration.enableLowLightBoost != device.automaticallyEnablesLowLightBoostWhenAvailable - if isDifferent && !device.isLowLightBoostSupported { + if device.automaticallyEnablesLowLightBoostWhenAvailable != configuration.enableLowLightBoost { + guard device.isLowLightBoostSupported else { throw CameraError.device(.lowLightBoostNotSupported) } device.automaticallyEnablesLowLightBoostWhenAvailable = configuration.enableLowLightBoost } // Configure Torch - if configuration.torch != .off { + let torchMode = configuration.torch.toTorchMode() + if device.torchMode != torchMode { guard device.hasTorch else { throw CameraError.device(.flashUnavailable) } - - device.torchMode = configuration.torch.toTorchMode() - try device.setTorchModeOn(level: 1.0) + device.torchMode = torchMode + if torchMode == .on { + try device.setTorchModeOn(level: 1.0) + } } }