// // SGTorch.m // SGQRCodeExample // // Created by kingsic on 2022/7/9. // Copyright © 2022 kingsic. All rights reserved. // #import "SGTorch.h" #import @implementation SGTorch + (void)turnOnTorch { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if ([device hasTorch]) { BOOL locked = [device lockForConfiguration:nil]; if (locked) { [device setTorchMode:AVCaptureTorchModeOn]; [device unlockForConfiguration]; } } } + (void)turnOffTorch { AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; if ([device hasTorch]) { [device lockForConfiguration:nil]; [device setTorchMode:AVCaptureTorchModeOff]; [device unlockForConfiguration]; } } @end