@IBAction func lightButtonClick(_ sender: UIButton) {
let device = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
if device == nil {
sender.isEnabled = false
return
}
if device?.torchMode == AVCapturetorchMode.off{
do {
try device?.lockForConfiguration()
} catch {
return
}
device?.torchMode = .on
device?.unlockForConfiguration()
sender.isSelected = true
}else {
do {
try device?.lockForConfiguration()
} catch {
return
}
device?.torchMode = .off
device?.unlockForConfiguration()
sender.isSelected = false
}
}