我只想打开LED灯。有没有一种简单的方法可以做到这一点,或者我是否需要设置手机拍摄视频,模拟视频开启,但不保存视频?那样的东西?感谢。
答案 0 :(得分:2)
试试这个,它对我来说很好。
#import <AVFoundation/AVFoundation.h>
- (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];
}
}
}