カメラのライトを使おうとしたら下記エラーに遭遇しました。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[AVCaptureDevice setTorchModeOnWithLevel:error:] The passed torchLevel 0.000000 is invalid'
ドキュメントにはこのメソッドに渡すパラメータの説明が 0.0 ~ 1.0 の浮動小数点数とあるのだが...
The new torch mode level. This value must be a floating-point number between 0.0 and 1.0. To set the torch mode level to the currently available maximum, specify the constant AVCaptureMaxAvailableTorchLevel for this parameter.
下記のようにして回避しました。
try? videoDevice.lockForConfiguration()
if newValue > 0.1 {
try? videoDevice.setTorchModeOn(level: newValue)
} else {
videoDevice.torchMode = .off
}
videoDevice.unlockForConfiguration()