iOS中许多手电筒应用的LED SOS模式是怎么写的?官方好像没有提供代码片段。求解答。
- (void)changeFlash:(BOOL)isOpened{
NSLog(@"changed the flash:%d",isOpened);
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([device hasTorch]) {
[device lockForConfiguration:nil];
if(isOpened)
[device setTorchMode:AVCaptureTorchModeOn]; // use AVCaptureTorchModeOff to turn off
else
[device setTorchMode:AVCaptureTorchModeOff];
[device unlockForConfiguration];
}
}
多看文档是王道~
AVCaptureTorchModeOn 是常亮,Auto是拍的时候有可能亮有可能不亮。