You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

35 lines
856 B

//
// SGTorch.m
// SGQRCodeExample
//
// Created by kingsic on 2022/7/9.
// Copyright © 2022 kingsic. All rights reserved.
//
#import "SGTorch.h"
#import <AVFoundation/AVFoundation.h>
@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