可以设置一个全局变量isTurnON去记录闪光灯是否开启,一次来判断点击按钮时关闭还是开启闪光灯
```AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];</code>
if ([device hasTorch]) {
if (isTurnON) {
[device lockForConfiguration:nil];
[device setTorchMode: AVCaptureTorchModeOff];//关
[device unlockForConfiguration];
}else
{
[device lockForConfiguration:nil];
[device setTorchMode: AVCaptureTorchModeOn];//开
[device unlockForConfiguration];
}
isTurnON = !isTurnON;
}
```
如此, 一个简单的闪光灯的控制就完成了