Skip to content

Instantly share code, notes, and snippets.

// Swift 2.0 port of Objective-C code: http://www.theappguruz.com/blog/onoff-flashlight-one-button-ios
// Usage: AVCaptureDevice.turnLight()
// It does not work simultaneously with system turn of the torch
import AVFoundation
extension AVCaptureDevice {
static func turnLight() {
let device = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
if ( device.isTorchModeSupported(AVCaptureTorchMode.On) && device.isTorchModeSupported(AVCaptureTorchMode.Off)) {