Skip to content

Instantly share code, notes, and snippets.

@adison
Created August 20, 2014 05:25
Show Gist options
  • Save adison/9a93aa7b0935befd46e0 to your computer and use it in GitHub Desktop.
Save adison/9a93aa7b0935befd46e0 to your computer and use it in GitHub Desktop.
flash light test snippet
// from http://stackoverflow.com/questions/11726543/how-to-turn-flashlight-on-off-using-one-button
AVCaptureDevice *flashLight = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
if ([flashLight isTorchAvailable] && [flashLight isTorchModeSupported:AVCaptureTorchModeOn])
{
BOOL success = [flashLight lockForConfiguration:nil];
if (success)
{
if ([flashLight isTorchActive]) {
[flashLight setTorchMode:AVCaptureTorchModeOff];
} else {
[flashLight setTorchMode:AVCaptureTorchModeOn];
}
[flashLight unlockForConfiguration];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment