How to check on/off status of Flashlight / Torch / Flash

I would like to know if the user has turned on the light over the control center before starting the app. I have a whole simple test app with the following code in the viewDidLoad


.

for(AVCaptureDevice *device in [AVCaptureDevice devices]){ 
     if ([device isTorchAvailable] && [device hasTorch] ){
           NSLog(@"%ld - %ld - %@ - %.2f - %@", device.torchMode, 
                                                device.flashMode, 
                                                device.isFlashActive ? @"yes" : @"no", 
                                                device.torchLevel, 
                                                device.isTorchActive ? @"yes" : @"no"
          ); 
     }
 }

The light will turn on and the app will start. But it returns allways:
0 - 0 - no - 0.00 - no

It says:
AVCaptureDevice *device;

device.torchMode = AVCaptureTorchModeOff
device.flashMode = AVCaptureFlashModeOff
device.isFlashActive = NO
device.torchLevel = 0.0f
device.isTorchActive = NO



Problem:

I am told "not active" however the flashlight of the Device is ON. It was switched on in the control center. Why can't I grab this information?

Replies

See Demo Project
https://github.com/StefaniOSApps/TestFlash



This helps to check the current flashlight status.