views:

98

answers:

1
-(IBAction)turningFlashOn:(id)sender
{
AVCaptureSession *captureSession = [[AVCaptureSession alloc] init];
AVCaptureDevice *videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError *error = nil;
AVCaptureDeviceInput *videoInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];

if (videoInput) {
    [captureSession addInput:videoInput];



    AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];
    [videoOutput setSampleBufferDelegate:self queue:dispatch_get_current_queue()];
    [captureSession addOutput:videoOutput];
    [captureSession startRunning];
    videoCaptureDevice.torchMode = AVCaptureFlashModeOn;
}
}

I am being asked to use lockForConfiguration but it doesn't work or maybe i'm using it wrong. Can anyone please tell me what I'm doing wrong?

+1  A: 
if([videoCaptureDevice lockForConfiguration]) {
  [videoCaptureDevice setTorchMode:AVCaptureTorchModeOn];
  [videoCaptureDevice unlockForConfiguration];
 }
gnuchu
How do you shut it off when you're done using TourchModeOn
Cocoa Dev
[videoCaptureDevice setTorchMode:AVCaptureTorchModeOff];or just release your AVCaptureSession object. Which ever is more appropriate.
gnuchu
You should probably call `[session stopRunning];` before releasing the session. See my post here: http://stackoverflow.com/questions/3190034/turn-on-torch-flash-on-iphone-4/3367424#3367424
iWasRobbed