Coder Social home page Coder Social logo

Comments (14)

jeryRazakarison avatar jeryRazakarison commented on September 26, 2024 2

Just one thing to know: when you call controller.reset(), it tells the scanner that it can capture new barcodes.
So, if you call controller.reset() in the didCaptureCode delegate (like in the example), you tell the scanner that it can scan again as soon as a barcode is scanned.

from barcodescanner.

vadymmarkov avatar vadymmarkov commented on September 26, 2024

@githotto Hey, did you change isOneTimeSearch property to false? Because setting it to true should prevent delegate from being called multiple times.

from barcodescanner.

githotto avatar githotto commented on September 26, 2024

@vaymmarkov Hey, I tried indeed setting isOneTimeSearch to true, but with no noticeable improvement. However when I set the scannerController.codeDelegate, .errorDelegate and .dismissalDelegate to nil in my controller.reset() func, my problems seem to have gone. Should the isOneTimeSearch have the same effect or was it just me (after a long day of bug-fixing), because today your suggestions also seems to work!?

from barcodescanner.

MincDev avatar MincDev commented on September 26, 2024

@jeryRazakarison Thank you. That solved my problem!

from barcodescanner.

junweimah avatar junweimah commented on September 26, 2024

@MincDev how did you solve this?

I have controller.isOneTimeSearch = true in my viewDidLoad(), but it still scans for multiple times after the barcodecontroller has been dismissed.

from barcodescanner.

MincDev avatar MincDev commented on September 26, 2024

@junweimah Remove the controller.reset() from the didCaptureCode delegate function. In the delegate function do what you need to do with the captured code and call controller.dismiss(animated: true, completion: nil) to dismiss the controller.

from barcodescanner.

junweimah avatar junweimah commented on September 26, 2024

@MincDev
I did that, it goes back to the previous screen, however the cpu is on 100% all the time after that, and device becomes really hot. any idea?

from barcodescanner.

MincDev avatar MincDev commented on September 26, 2024

@junweimah I am not sure as mine immediately stops the scanning process and my CPU never reaches 100%. I had the same issue with the scanner scanning multiple times and removing the controller.reset() solved it for me. What I am doing is scanning the code, then in the didCaptureCode delegate function I am querying the code against a barcode API that returns details. I completely removed the controller.reset() function from the delegate.

from barcodescanner.

junweimah avatar junweimah commented on September 26, 2024

@MincDev
This is my current didCaptureCode function

func barcodeScanner(_ controller: BarcodeScannerController, didCaptureCode code: String, type: String) {
        print("Barcode Data: \(code)")
        print("Symbology Type: \(type)")
        controller.isOneTimeSearch = true
        
        Timer.scheduledTimer(withTimeInterval: 1.0, repeats: false) { _ in
//            controller.reset(animated: true)
            controller.dismiss(animated: true, completion: nil)
        }
}

After a successful scanning, the screen will go back my previous screen, because of controller.dismiss, but my cpu goes up to 100%.

I click my scan button to bring user back to the scanning screen, but the 'Looking for your product' loading screen is still there, which is why I am guessing cpu is at 100% all the time.

How do I close the loading other than .reset?

from barcodescanner.

MincDev avatar MincDev commented on September 26, 2024

@junweimah remove the ‘controller.reset(animated: true) from the function. It is not needed here. If you call it the you are telling the scanner it is ready again to scan. Now you close it while you told it to get ready for scanning and that is why your cpu is at 100%. Just remove the reset and you will see everything wil work

from barcodescanner.

junweimah avatar junweimah commented on September 26, 2024

@MincDev
Actually i commented off that part. I try scanning for the first time, and then try to scan again to test whether it is running in the background, and I found that it won't scan for the second time, which is working.

But for some reason when I come back to the scanning screen, the loading screen(with the spinning square) is still there

from barcodescanner.

MincDev avatar MincDev commented on September 26, 2024

@junweimah I also do not have the ‘isOneTimeSearch = false’ in my delegate. I have nothing other than dismiss and just calling a function to for the API. Try taking the dismiss out of the scheduled timer. If that still doesnt work, then the problem is somewhere else. Maybe in the way you call the scanner to open?

from barcodescanner.

junweimah avatar junweimah commented on September 26, 2024

@MincDev
Possibly, ill have a further look, thanks

from barcodescanner.

vadymmarkov avatar vadymmarkov commented on September 26, 2024

As I commented before, setting isOneTimeSearch property to true prevents delegate from being called multiple times. Please also note that you should set this property before you present BarcodeScannerViewController.

from barcodescanner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.