I went through the same issue as yours.
iOS supports two modes - Flash Light & Torch. The code below checks if each is available & then if turns them on or off depending on which one you call. Also it checks if the light is already on/off.
Flash On -
-(void)flashOn {
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
if ([device hasFlash]) {
if ([device flashMode] == AVCaptureFlashModeOff) {
[device setFlashMode:AVCaptureFlashModeOn];
}
}
if ([device hasTorch]) {
if ([device torchMode] == AVCaptureTorchModeOff) {
[device setTorchMode:AVCaptureTorchModeOn];
}
}
[device unlockForConfiguration];
}
}
Flash Off-
-(void)flashOff {
Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
if (captureDeviceClass != nil) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
if ([device hasFlash]) {
if ([device flashMode] == AVCaptureFlashModeOn) {
[device setFlashMode:AVCaptureFlashModeOff];
}
}
if ([device hasTorch]) {
if ([device torchMode] == AVCaptureTorchModeOn) {
[device setTorchMode:AVCaptureTorchModeOff];
}
}
[device unlockForConfiguration];
}
}