Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Prevent multiple calls to scanner
Browse files Browse the repository at this point in the history
Scanner freezes in IOS if multiple calls to the barcode scanner are made at the same time
  • Loading branch information
wodka authored and daserge committed Jun 22, 2016
1 parent 55e6938 commit 2aa5bdc
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion www/barcodescanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

var exec = require("cordova/exec");

var scanInProgress = false;

/**
* Constructor.
*
Expand Down Expand Up @@ -97,7 +99,26 @@ BarcodeScanner.prototype.scan = function (successCallback, errorCallback, config
return;
}

exec(successCallback, errorCallback, 'BarcodeScanner', 'scan', config);
if (scanInProgress) {
errorCallback('Scan is already in progress');
return;
}

scanInProgress = true;

exec(
function(result) {
scanInProgress = false;
successCallback(result);
},
function(error) {
scanInProgress = false;
errorCallback(error);
},
'BarcodeScanner',
'scan',
config
);
};

//-------------------------------------------------------------------
Expand Down

0 comments on commit 2aa5bdc

Please sign in to comment.