2

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 ?

See http://community.phonegap.com/nitobi/topics/_barcodescanner_plugin_upgrading_scanner_javascript_api_code_changes_required :

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.

Community
  • 1
  • 1
Neme Zya
  • 45
  • 4

1 Answers1

0

For some reason, the culprit was a Monaca debugger parameter :

In Monaca app > Debugger settings > Turn off "Restart after resume"

Neme Zya
  • 45
  • 4