判断是否存在手电筒
@property(nonatomic, readonly) BOOL hasTorch;
检测手电筒是否可用
例如:例如设备过热,需要降温。此属性键值可观测
@property(nonatomic, readonly, getter=isTorchAvailable) BOOL torchAvailable
检测手电筒是否正在使用
@property(nonatomic, readonly, getter=isTorchActive) BOOL torchActive
手电筒模式
@property(nonatomic) AVCaptureTorchMode torchMode;
手电筒模式:打开 关闭 自动
typedef NS_ENUM(NSInteger, AVCaptureTorchMode) {
AVCaptureTorchModeOff = 0,
AVCaptureTorchModeOn = 1,
AVCaptureTorchModeAuto = 2,
} NS_AVAILABLE(10_7, 4_0) __TVOS_PROHIBITED;
设置手电筒亮度[0~1]之间
该值只在AVCaptureTorchModeOn 模式下有效
- (BOOL)setTorchModeOnWithLevel:(float)torchLevel error:(NSError * _Nullable * _Nullable)outError NS_AVAILABLE_IOS(6_0);
更改手电筒模式及亮度的时候必须先锁定设备,修改完后再解锁,否则崩溃
[device lockForConfiguration:nil];
//设置闪光灯为自动
[device setFlashMode:AVCaptureTorchModeOn];
[captureDevice setTorchModeOnWithLevel:.2 error:nil];
[device unlockForConfiguration];
检测是否支持某种手电筒模式
- (BOOL)isTorchModeSupported:(AVCaptureTorchMode)torchMode;