Last active
December 14, 2022 01:47
-
-
Save 1998code/9e47504dc2940f154e6282191c5b5260 to your computer and use it in GitHub Desktop.
Torch Light Function
This file contains 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
import SwiftUI | |
import AVFoundation | |
func toggleTorch(on: Bool) { | |
guard let device = AVCaptureDevice.default(for: .video) else { return } | |
if device.hasTorch { | |
do { | |
try device.lockForConfiguration() | |
device.torchMode = on ? .on : .off | |
device.unlockForConfiguration() | |
} catch { | |
print("Torch could not be used") | |
} | |
} else { | |
print("Torch is not available") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment