I'm using AVCaptureDevice.setTorchModeOn(level)
method to turn on the flashlight at variable brightness.
On my old iPhone SE it's working fine — I can clearly see 4 different brightness levels as I change level
from 0
to 1
.
But on the iPhone 11 Pro the flashlight turns on only when level is 1.0
! And it's brightness if far from maximum level (compared to flashlight from Control Center).
I tried using maxAvailableTorchLevel
constant, but results are the same as using 1.0
.
Also tried values more than 1.0
— this results in exception (as expected).
Did anyone have this problem too? Maybe there are some workarounds?
According to the documentation for maxAvailableTorchLevel
If this constant always represents the maximum available torch level, we not only extract that different devices have different maximum available levels but also that the device you mention can't go higher than 1.0.
Best one can do now is to reach out to Apple's developer support.
I remembered that back in the iOS 3.x days we didn't have simple LED API. We had to start a full video capture session. Well it turns out that with the iPhone 11 this seems to be the only solution. I'd love to hear about others which don't require this.
This is my tested workaround. I am using Objective C here, not Swift because that's what I used in this old app from 2009! You can easily find Swift code to start video capture (and ignore the output, it should work the same.
And after this you just start the LED as usual:
This gets maximum brightness on my iPhone 11 Pro. I am now looking for the same solution without having to use the video capture (which obviously uses battery AND requires a permission, which users may not like. It needs to be explained well).