I'm trying to make an iOS app where I can turn the torch on and change the brightness.
I'm testing it on iPhone 11 with iOS 13.3.1 and Xcode 11.3.1
I used one of the solutions here: How to turn flashlight ON and OFF in swift?
Everything works perfectly if I use:
try self.device.setTorchModeOn(level: AVCaptureDevice.maxAvailableTorchLevel)
I can turn it on and off freely.
but if I try to change the brightness like this (using var someFloat: Float
from 0.1 to 1):
try self.device.setTorchModeOn(level: someFloat)
everything goes haywire. The brightness dims, but then dims too much. Then, even if I use AVCaptureDevice.maxAvailableTorchLevel
, it stays extremely dim. And the only way to restore it is to restart my iPhone. Then it's bright again until I try to mess with the level.
Anyone seen this?