I built a camera app for auto capture. I want to keep the flash on as long as the camera is on. I set the following code :
 cameraDevice = AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo)
    if (cameraDevice.hasTorch) {
        do {
            try cameraDevice.lockForConfiguration()
            if cameraDevice.isTorchActive {
                cameraDevice.torchMode = AVCaptureTorchMode.on
            } else {
                // sets the torch intensity to 100%
               try  cameraDevice.setTorchModeOnWithLevel(0.8)
            }
            cameraDevice.unlockForConfiguration()
        } catch {
            print(error)
        }
    }
But when I run the app, it only flashes for one time and then goes off. How can I solve this problem?