0

When I'm running the app in iPhone 6S with iOS 11.2.2. The Flash is not working. Toggle button is working fine i.e., On/Off. But, Flash is not coming when the toggle is On.

- (void)toggleFlash{
        NSArray *devices = [AVCaptureDevice devices];
        for (AVCaptureDevice *device in devices){
            if (device.flashAvailable) {
                if (flashOn){
                    [device lockForConfiguration:nil];
                    [device isTorchModeSupported:AVCaptureTorchModeOn];
                    [device unlockForConfiguration];
                }
                else{
                    [device lockForConfiguration:nil];
                    [device isTorchModeSupported:AVCaptureTorchModeOff];
                    [device unlockForConfiguration];
                }
            }
        }
    }

Done with the debugging.. It's working fine. But, Issue with Flash. Anyone Working on this issue. Please help me out?

rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

Your code only checks whether torch mode is available (isTorchModeSupported) but never turns on the torch. You can use setTorchModeOn for that,

dr_barto
  • 5,723
  • 3
  • 26
  • 47
  • I'm using MACaptureSession., setTorchMode is not visible on MACaptureSession. – Prathap Reddy Jakkireddy Jan 27 '18 at 13:07
  • - (void)toggleFlash { if (flashIsOn) { flashIsOn = NO; [_captureManager setFlashOn:NO]; [_flashButton setImage:[UIImage imageNamed:@"flash-off-button"]]; _flashButton.accessibilityLabel = @"Enable Camera Flash"; [self storeFlashSettingWithBool:NO]; } else { flashIsOn = YES; [_captureManager setFlashOn:YES]; [_flashButton setImage:[UIImage imageNamed:@"flash-on-button"]]; _flashButton.accessibilityLabel = @"Disable Camera Flash"; [self storeFlashSettingWithBool:YES]; } } – Prathap Reddy Jakkireddy Jan 27 '18 at 13:08
  • This is the code for Torchmode i writen in another class. – Prathap Reddy Jakkireddy Jan 27 '18 at 13:08
  • In your code the variable `device` is of type `AVCaptureDevice`, which definitely has that method: https://developer.apple.com/documentation/avfoundation/avcapturedevice/1624609-settorchmodeon – dr_barto Jan 27 '18 at 13:10