I'm making an app to allow me to stitch images together into a panoramic scene. I want to be able to turn the Flash LED on the iPhone 4 programatically.
How can I do this?
I read the documentation and discovered that I need to use AVCaptureFlashMode
but I can't figure out how 2 use it?
any help would be appreciated.
Updated Code below. Thanks SIF!
NSError* error = nil;
NSLog(@"Setting up LED");
if([captDevice hasTorch] == NO)
{
NSLog(@"Error: This device doesnt have a torch");
}
if([captDevice isTorchModeSupported:AVCaptureTorchModeOn] == NO)
{
NSLog(@"Error: This device doesnt support AVCaptureTorchModeOn");
}
AVCaptureSession* captureSession = [[AVCaptureSession alloc] init];
AVCaptureDeviceInput* videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:captDevice error:&error];
AVCaptureVideoDataOutput* videoOutput = [[AVCaptureVideoDataOutput alloc] init];
if (videoInput && videoOutput)
{
[captureSession addInput:videoInput];
[captureSession addOutput:videoOutput];
if([captDevice lockForConfiguration:&error])
{
if (flag == YES) {
captDevice.torchMode = AVCaptureTorchModeOn;
} else {
captDevice.torchMode = AVCaptureTorchModeOff;
}
[captDevice unlockForConfiguration];
}
else
{
NSLog(@"Could not lock device for config error: %@", error);
}
[captureSession startRunning];
}
else
{
NSLog(@"Error: %@", error);
}
How do you turn it off?