I am currently trying Monaca to develop an hybrid app using the Cordova barcode scanner plugin.
For some reason, scan callback started to behave not properly.
Immediatly after scanning, I get a syncing message dialog ("checking sync target files..."), then a "downloading files" dialog and then, finally, the result dialog I asked for. After closing my result dialog, app goes back to index page, which I do not want.
Here is my code (I use Onsen UI):
js/app.js
var app = angular.module('hello', ['onsen']);
app.controller('testController', ['$scope',function($scope) {
$scope.scan = function() {
window.plugins.barcodeScanner.scan(function(result) {
alert( result.text);
}, function(error) {
alert('scan error');
});
}
}]);
index.html
<!DOCTYPE HTML>
<html ng-app="hello">
<head>
<title>Barcode</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no">
<script src="components/loader.js"></script>
<link rel="stylesheet" href="components/loader.css">
<script src="js/app.js"></script>
</head>
<body>
<div ng-controller="testController">
<input type="button" ng-click="scan()" value ="Scan !" />
</div>
</body>
</html>
Maybe it is related to the way plugin now has to be called ?
The BarcodeScanner Plugin on PhoneGap Build will be getting an update today, and apps using it will need to change their code to use cordova.require:
Old:
window.plugins.barcodeScanner.scan(function(){ ... }, function(){ ... }, optionsObj)
New:
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan(function (result) {...}, function (error) {...});
Thanks for your help.