我正在使用Apple的AVCam source code 创建自定义相机,我试图打开/关闭闪光灯,但它无法正常工作。这是我的代码,不知道出了什么问题。我是AVCam的新手。
- (void) toggleFlash:(id)sender {
dispatch_async([self sessionQueue], ^{
AVCaptureDevice *currentVideoDevice = [[self videoDeviceInput] device];
AVCaptureDevicePosition currentPosition = [currentVideoDevice position];
if(currentPosition == AVCaptureDevicePositionUnspecified || currentPosition == AVCaptureDevicePositionBack) {
if([currentVideoDevice hasFlash]) {
[currentVideoDevice lockForConfiguration:nil];
[currentVideoDevice setFlashMode:AVCaptureFlashModeOn];
[currentVideoDevice unlockForConfiguration];
}
}
});
}
它通过代码中的每一行,并没有记录任何错误,但仍然没有运气。
答案 0 :(得分:0)
- (void) toggleFlash {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch] && [device hasFlash]){
[device lockForConfiguration:nil];
[device setTorchMode:!device.torchActive];
[device setFlashMode:!device.torchActive];
[device unlockForConfiguration];
}
}
P.S。在我的情况下,火炬/闪光灯最初关闭。