- (void) turnTorchOn: (bool) on { Class captureDeviceClass = NSClassFromString(@"AVCaptureDevice"); if (captureDeviceClass != nil) { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if ([device hasTorch] && [device hasFlash]){ [device lockForConfiguration:nil]; if (on) { [device setTorchMode:AVCaptureTorchModeOn]; [device setFlashMode:AVCaptureFlashModeOn]; torchIsOn = YES; } else { [device setTorchMode:AVCaptureTorchModeOff]; [device setFlashMode:AVCaptureFlashModeOff]; torchIsOn = NO; } [device unlockForConfiguration]; } } }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/3328.html