imaginary-cloud / CameraManager

Simple Swift class to provide all the configurations you need to create custom camera view in your app
MIT License
1.37k stars 324 forks source link

QR Detection Only Works Once Per Session #244

Open Yrban opened 3 years ago

Yrban commented 3 years ago

When I trigger the QR detection via the following code, it will only read one QR code. My code:

    fileprivate func startQRCodeDetection() {
        cameraManager.startQRCodeDetection { (result) in
            switch result {
            case .success(let value):
                qrString = value
            case .failure(let error):
                NSLog("\ncameraManager.startQRCodeDetection failed with error %@", error.localizedDescription)
            }
        }
        qrScannerIsActive = true
    }

    fileprivate func stopQRCodeDetection() {
        cameraManager.stopQRCodeDetection()
        qrScannerIsActive = false
        qrString = nil
    }

I think I traced one issue to stopQRCodeDetection() in CameraManager. Line 821 fails and I otherwise can't see where qrOutput is ever set to anything from nil, therefore, line 822, captureSession?.removeOutput(output) is not called. I am not sure that that is the root of my problem that I am seeing, but it may need addressing. Thanks.