0
Button(action: {
    DispatchQueue.global(qos: .userInteractive).async {
        self.lightOn.toggle()
        
        let cam = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back)
        
        try? cam?.lockForConfiguration()
        
        if (cam?.torchMode == AVCaptureDevice.TorchMode.on) {
            cam?.torchMode = AVCaptureDevice.TorchMode.off
        }
        else if value == 0.0 {
            do {
                try cam?.setTorchModeOn(level: 0.05)
            }
            catch {
                print(error)
            }
        }
        else  {
            do {
                try cam?.setTorchModeOn(level: value)
            }
            catch {
                print(error)
            }
        }
        
        cam?.unlockForConfiguration()
    }
})

I've tried gos:.userInteractive, userInitiated, utilities and background but it doesn't seems to work. Anyone can let me know what went wrong?

zhulien
  • 5,145
  • 3
  • 22
  • 36
Ernest Tan
  • 11
  • 4
  • This doesn't have anything to do with starting it on a certain thread. It's a system limitation. See: https://stackoverflow.com/a/32137434/560942 – jnpdx Mar 13 '21 at 20:48
  • I see. Thank you very much for the info. It helps a lot! – Ernest Tan Mar 17 '21 at 04:27

0 Answers0