vinodiOS/SwiftQRCodeScanner

Scanner viewcontroller dimming transparency

Closed this issue · 2 comments

Hi cool lib, but I have a small problem. I have a very simple scanner controller...

import UIKit
import SwiftQRScanner

class ScannerViewController: UIViewController {
    
    let scanner = QRCodeScannerController()
    var scanedData: String!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        scanner.delegate = self
    }
    
    override func viewWillAppear(_ animated: Bool) {
        
    }
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if segue.identifier == "ProductDetailsSegue" {
            let destinationVC = segue.destination as! ProductDetailsViewController
            destinationVC.scanedItemId = scanedData
        }
    }

    @IBAction func scan(_ sender: Any) {
        scanner.modalPresentationStyle = .fullScreen
        present(scanner, animated: true, completion: nil)
    }
}

extension ScannerViewController: QRScannerCodeDelegate {
    
    func qrScannerDidCancel(_ controller: UIViewController) {
        print("Scann Canceled")
    }
    
    func qrScannerDidFail(_ controller: UIViewController, error: String) {
        print("Scann Failed: \(error)")
    }
    
    func qrScanner(_ controller: UIViewController, scanDidComplete result: String) {
        print("Scann Completed =======>")
        scanedData = result
        print(result)
        controller.dismiss(animated: true) {
            self.performSegue(withIdentifier: "ProductDetailsSegue", sender: self)
        }
        
    }
}

It all works fine, except every time I present the scanner view controller, the screen gets dimmer and dimmer, until its all black and only the "aim" rectangle is seen, I don't see anything through the camera.

File

I'm not sure if my implementation is wrong or it's some kind of a bug. Any thoughts?

@Struki84 thanks for the feedback. Global declaration of QRCodeScannerController causing the memory leak issue. So create scanner instance in scan function itself. This will solve your problem.

Yep I figured it out about an hour after I posted the question, forgot to write up a reply. Ty anyways, this can be closed now. I'm hoping will be helpful to other ppl if they come by the same problem. Once again, rly nice lib, simple, easy to use, GJ!