-(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?
if([videoCaptureDevice lockForConfiguration]) {
[videoCaptureDevice setTorchMode:AVCaptureTorchModeOn];
[videoCaptureDevice unlockForConfiguration];
}
- (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];
}
}
}
精彩评论