Skip to content

Instantly share code, notes, and snippets.

@rtking1993
Last active February 12, 2019 11:19
Show Gist options
  • Save rtking1993/3e251fc1556f91dd1bc3eb006bbd416b to your computer and use it in GitHub Desktop.
Save rtking1993/3e251fc1556f91dd1bc3eb006bbd416b to your computer and use it in GitHub Desktop.
Small function to use torch
func setTorch(on: Bool) {
guard let device = AVCaptureDevice.default(for: AVMediaType.video),
device.hasTorch else {
return
}
do {
try device.lockForConfiguration()
if on {
do {
try device.setTorchModeOn(level: 1.0)
} catch {
print(error)
}
} else {
device.torchMode = AVCaptureDevice.TorchMode.off
}
device.unlockForConfiguration()
} catch {
print(error)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment