suvish valsan
suvish valsan

Reputation: 869

IOS8 torch turns on when dark, inspite of setting AVCaptureTorchModeOff

used below code to disable torch was working fine in ios7 , but in ios8 torch gets on when dark

 AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
                    if ([device hasTorch] || [device hasFlash]){
                        [device lockForConfiguration:nil];
                        [device setTorchMode:AVCaptureTorchModeOff];
                        [device setFlashMode:AVCaptureFlashModeOff];
                        [device unlockForConfiguration];
                    }

Upvotes: 1

Views: 235

Answers (1)

Naveen kumar
Naveen kumar

Reputation: 800

Try this code it works...

 - (IBAction)flashOnClicked:(id)sender
    {
        AVCaptureDevice *flashLight = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
        if ([flashLight isTorchAvailable] && [flashLight isTorchModeSupported:AVCaptureTorchModeOn])
        {
            BOOL success = [flashLight lockForConfiguration:nil];
            if (success)
            {
                if ([flashLight isTorchActive])
                {
                    //TURN ON
                    [flashLight setTorchMode:AVCaptureTorchModeOff];
                }
                else
                {
                    //TURN OFF
                    [flashLight setTorchMode:AVCaptureTorchModeOn];
                }
                [flashLight unlockForConfiguration];
            }
        }
    }

Upvotes: 2

Related Questions