Skip to content

Instantly share code, notes, and snippets.

@saturngod
Created April 17, 2012 04:49
Show Gist options
  • Select an option

  • Save saturngod/2403511 to your computer and use it in GitHub Desktop.

Select an option

Save saturngod/2403511 to your computer and use it in GitHub Desktop.
flash light with iOS
//need to use AVFoundation framework
/*
#import <AVFoundation/AVFoundation.h>
*/
if(!self.flashOn) {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOn];
[device setFlashMode:AVCaptureFlashModeOn];
[device unlockForConfiguration];
self.flashOn=YES;
[btn setImage:[UIImage imageNamed:@"light_on.png"] forState:UIControlStateNormal];
}
else {
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
[device lockForConfiguration:nil];
[device setTorchMode:AVCaptureTorchModeOff];
[device setFlashMode:AVCaptureFlashModeOff];
[device unlockForConfiguration];
self.flashOn=NO;
[btn setImage:[UIImage imageNamed:@"light.png"] forState:UIControlStateNormal];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment