Reputation: 9551
-(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?
Upvotes: 0
Views: 571
Reputation: 93
- (void)flashLightOn {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices) {
if ([device hasFlash] == YES) {
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn];
[device unlockForConfiguration];
}
}
}
-(void)flashLightOff {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices) {
if ([device hasFlash] == YES) {
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOff];
[device unlockForConfiguration];
}
}
}
Upvotes: 1
Reputation: 1496
if([videoCaptureDevice lockForConfiguration]) {
[videoCaptureDevice setTorchMode:AVCaptureTorchModeOn];
[videoCaptureDevice unlockForConfiguration];
}
Upvotes: 2