This is a migrated thread and some comments may be shown as answers.

Cordova Scanner cancel propagation

2 Answers 101 Views
General Discussion
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Martin Roussel
Top achievements
Rank 1
Martin Roussel asked on 31 Dec 2013, 01:06 AM
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 Answers, 1 is accepted

Sort by
0
Martin Roussel
Top achievements
Rank 1
answered on 31 Dec 2013, 08:36 PM
Please someone move this post to the Cordova forum

sorry for this

TIA
0
iliev
Telerik team
answered on 01 Jan 2014, 09:33 AM
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
Tags
General Discussion
Asked by
Martin Roussel
Top achievements
Rank 1
Answers by
Martin Roussel
Top achievements
Rank 1
iliev
Telerik team
Share this question
or