Cordova Scanner cancel propagation

3 posts, 0 answers
  1. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 30 Dec 2013 Link to this post

    Hi,

    im testing the Cordova  (3.2.0)  Barcode Scanner plugin on a iPhone 4S (7.0.4) and have an issue with the scanning function

    cordova.plugins.barcodeScanner.scan(
                                function(result) {
                                    if (!result.cancelled) {
                                        $("#result").text(result.format + " | " + result.text);
                                    }
                                },
                                function(error) {
                                     alert("failed");
                                    console.log("Scanning failed: " + error);
                                });

    the problem is if I insert an alert into the function (result) {} block, It keeps appearing forever (im stuck in the alert popup). Must I cancel the event propagation somehow? If yes how?  Im checking at the doc on the GitHub repository here and seems like we dont have to (even If I have the same issue with that code).

    Im asking because I want to call a webservice after the scan and afraid to call it forever for the same scan.

    you can use my MIST sample called sample-barcode-scanner for testing my issue

    TIA


  2. Martin Roussel
    Martin Roussel avatar
    246 posts
    Member since:
    Jan 2010

    Posted 31 Dec 2013 Link to this post

    Please someone move this post to the Cordova forum

    sorry for this

    TIA
  3. iliev
    Admin
    iliev avatar
    36 posts

    Posted 01 Jan 2014 Link to this post

    Hello Martin,

    I've investigated your application and this is expected javascript behavior. Functions like alert stop the execution completely until they return. As a result of this you can try calling your alert inside setTimeout(). You may set the timeout to 0 ms so the function executes immediately without blocking.

    setTimeout(function() {
        alert(result.text);
    }, 0);

    Please refer to this stackoverflow thread for more information.

    Regards,
    iliev
    Telerik
Back to Top