2

Possible Duplicate:
Turn on torch/flash on iPhone 4

I just want to be able to turn on the led light. Is there a simple way to do this, or am I going to need to, say, set up the phone to take a video, simulate it videoing with the light on, but not save the video? Something like that? Thanks.

Community
  • 1
  • 1
marty
  • 391
  • 1
  • 7
  • 15

1 Answers1

2

Try this, it worked fine for me.

#import <AVFoundation/AVFoundation.h>


- (void) turnTorchOn: (bool) on {

  Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice");
  if (captureDeviceClass != nil) {
  AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
  if ([device hasTorch] && [device hasFlash]){
    [device lockForConfiguration:nil];
    if (on) {
        [device setTorchMode:AVCaptureTorchModeOn];
        [device setFlashMode:AVCaptureFlashModeOn];
        torchIsOn = YES;
    } else {
        [device setTorchMode:AVCaptureTorchModeOff];
        [device setFlashMode:AVCaptureFlashModeOff];
        torchIsOn = NO;            
    }
    [device unlockForConfiguration];
    }
  }
}
Tibidabo
  • 21,461
  • 5
  • 90
  • 86