iOS 如何打开后灯(闪光灯)
- (void)torchOnOrOff
{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
if (device.torchMode == AVCaptureTorchModeOff) {
[device setTorchMode: AVCaptureTorchModeOn];
}else{
[device setTorchMode: AVCaptureTorchModeOff];
}
[device unlockForConfiguration];
}
来判断该摄像头是否有提供闪光灯
我是要持续开启所以使用Torch Mode
lockForConfiguration跟unlockForConfiguration是配对的API
呼叫lockForConfiguration就可以控制硬件了
控制完毕后要呼叫unlockForConfiguration