LoginSignup
1
0

More than 5 years have passed since last update.

The passed torchLevel 0.000000 is invalid

Posted at

カメラのライトを使おうとしたら下記エラーに遭遇しました。

*** 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()
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0