I\'d like to add flashlight functionality to my app in Swift. How can I go about doing that?
Swift 4.2
if let device = AVCaptureDevice.default(for: AVMediaType.video) {
if (device.hasTorch) {
do {
try device.lockForConfiguration()
let torchOn = !device.isTorchActive
try device.setTorchModeOn(level: 1.0)
device.torchMode = torchOn ? AVCaptureDevice.TorchMode.on : AVCaptureDevice.TorchMode.off
device.unlockForConfiguration()
} catch {
print(error.localizedDescription)
}
}
}