18
15

More than 5 years have passed since last update.

[Swift] iOS のカメラのフラッシュを On/Off する

Last updated at Posted at 2015-06-17

Swift で書いてみました。

    func toggleTorch() {
        Logger.log("tapped")
        let avDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)

        if  avDevice.hasTorch {
            avDevice.lockForConfiguration(nil)
            avDevice.torchMode = AVCaptureTorchMode.Off == avDevice.torchMode ? AVCaptureTorchMode.On : AVCaptureTorchMode.Off
            avDevice.unlockForConfiguration()
        }
    }

あまり使う機会ないかもしれませんが。

18
15
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
18
15