Cocoa Dev
Cocoa Dev

Reputation: 9551

I just want to turn the flash on for stitching photo's I'm trying to use AVCaptureDevice and AVCaptureFlashModeOn

-(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

Answers (2)

Nikkie
Nikkie

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

gnuchu
gnuchu

Reputation: 1496

if([videoCaptureDevice lockForConfiguration]) {
  [videoCaptureDevice setTorchMode:AVCaptureTorchModeOn];
  [videoCaptureDevice unlockForConfiguration];
 }

Upvotes: 2

Related Questions