Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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