1、导入相应的库文件AVFoundation
2、
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if (![device hasTorch]) {
NSLog(@"no torch");
}else{
[device lockForConfiguration:nil];
if (!on) {
[device setTorchMode: AVCaptureTorchModeOn];
}
else
{
[device setTorchMode: AVCaptureTorchModeOff];
}
[device unlockForConfiguration];
}