Created
April 17, 2012 04:49
-
-
Save saturngod/2403511 to your computer and use it in GitHub Desktop.
flash light with iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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