不用问我为什么这么用,这个框架也没这么用过,是在网上找的一些资料加上自己看框架总结的一些东西,只作为参考学习所用
导入#import <AVFoundation/AVFoundation.h>框架
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *bt=[UIButton buttonWithType:UIButtonTypeCustom];
bt.backgroundColor=[UIColor blueColor];
[bt setTitle:@"闪光灯" forState:0];
[bt sizeToFit];
bt.center=self.view.center;
[bt addTarget:self action:@selector(btEvent:)
forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:bt];
}
-(void)btEvent:(UIButton *)sender{
//使用定时器
sosTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self
selector:@selector(open)
userInfo:nil
repeats:YES];
[sosTimer fire];
}
-(void)open{
AVCaptureSession * session = [[AVCaptureSession alloc]init];
AVCaptureDeviceInput *input =[AVCaptureDeviceInput deviceInputWithDevice:device
error:nil];
[session addInput:input];
AVCaptureVideoDataOutput * output = [[AVCaptureVideoDataOutput alloc]init];
[session addOutput:output];
[session beginConfiguration];
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn];
[device unlockForConfiguration];
[session commitConfiguration];
[session startRunning];
}
参考资料:
http://blog.163.com/chester_lp/blog/static/139794082012119112834437/
http://stackoverflow.com/questions/3204008/how-do-i-use-avcaptureflashmode/3204078#3204078