フラッシュを点灯させる方法
まずはImport
import AVFoundation
以下のコードを記述
func ledFlash(_ flg: Bool) {
guard let avDevice = AVCaptureDevice.default(for: .video) else { return }
if avDevice.hasTorch {
do {
try avDevice.lockForConfiguration()
avDevice.torchMode = flg ? .on : .off
avDevice.unlockForConfiguration()
} catch {
print("Torch could not be used")
}
}
}
使い方
点灯
ledFlash(true)
消灯
ledFlash(false)

