Turn on the light of the iOS device

This is a method using the flashlight programatically.
You can control turning on and off.

It can be controlled from AVCaptureDevice of AVFoundation.

1,Lit

let avCaptureDevice = AVCaptureDevice.default(for: AVMediaType.video)

if avCaptureDevice!.hasTorch, avCaptureDevice!.isTorchAvailable {
do {
try avCaptureDevice!.lockForConfiguration()
try avCaptureDevice!.setTorchModeOn(level: 1.0) // 0.0 ~ 1.0
} catch let error {
print(error)
}
avCaptureDevice!.unlockForConfiguration()
}

t can be lit at the maximum level even with torchMode = .on.
torchMode = .auto says, “The capture device continuously monitors the light level and uses the torch if necessary.”

2,Off

do {
try avCaptureDevice!.lockForConfiguration()
} catch let error {
print(error)
}
avCaptureDevice!.torchMode = .off
avCaptureDevice!.unlockForConfiguration()

🐣

****

Request for work:

rockyshikoku@gmail.com

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store