Skip to content

Freeze when Turn on the flashlight #140

@ximplia-paolo-pasianot

Description

@ximplia-paolo-pasianot

Good morning, I want to preface by saying that I'm not an experienced Swift and iOS programmer, but I think I've found a bug with the flashlight.
I've implemented the QR code reading library and added a button to toggle the flashlight on and off. However, when I activate the flashlight, the QR code reading screen freezes.

// QR Code part
CodeScannerView(
      codeTypes: [.qr],
      simulatedData: "result",
      completion: { result in
          switch result {
          case .success(let result):
              self.ticketScan.handleEvent(event: .OnCodeFound(ticket: result.string))
              break
          case .failure(let error):
              self.ticketScan.handleEvent(event: .OnError(.QRCodeScan))
          }
      }
)

//Toggle Flash
private func toggleFlash() {
        guard let device = AVCaptureDevice.default(for: .video) else { return }
               
        if device.hasTorch {
            do {
                try device.lockForConfiguration()
                if device.torchMode == .on {
                    device.torchMode = .off
                } else {
                    device.torchMode = .on
                }
                device.unlockForConfiguration()
            } catch {
                self.ticketScan.handleEvent(event: .OnError(.NoCamera))
            }
        } else {
            self.ticketScan.handleEvent(event: .OnError(.NoFlash))
        }
    }

Thank you very much for the time you've dedicated to me.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions