What we want is, we wanna capture image, after torched for few seconds. It's working fine from lowest to iPhoneX. Start from iPhone 11 to latest the torch is not turning off instantly, when the function called the torched off. It's turning off after a few milliseconds I guess, kind of delay in turning off. And after flash, few images are dim and dark. Trigger the torch method is look like below.
public func triggerFlash() {
sessionQueue.async {
if let device = self.device {
let milliseconds = 2000
let seconds: Double = Double(milliseconds / 1000)
if device.hasTorch {
do {
try device.lockForConfiguration()
// Set Torch brightness to max
try device.setTorchModeOn(level: AVCaptureDevice.maxAvailableTorchLevel)
device.torchMode = .on
device.unlockForConfiguration()
Logger.log("Torch On")
self.sessionQueue.asyncAfter(deadline: .now() + seconds) {
do {
let device = self.device!
try device.lockForConfiguration()
device.torchMode = .off
device.unlockForConfiguration()
Logger.log("Torch Off")
} catch {
Error.throwNative(result, "try device.lockForConfiguration() Failed in triggerFlash() \(error)")
}
}
} catch {
Error.throwNative(result, "try device.lockForConfiguration() Failed in triggerFlash() \(error)")
}
} else {
result(false)
}
} else {
Error.throwNative(result, "First select and start the camera")
return
}
}
}
You can see the flash light on the image that's showing after turning off