我目前正在尝试 Monaca 使用 Cordova 条形码扫描仪插件开发一个混合应用程序。
由于某种原因,扫描回调开始表现不正常。
扫描后,我立即收到一个同步消息对话框(“检查同步目标文件...”),然后是一个“正在下载文件”对话框,最后是我要求的结果对话框。关闭我的结果对话框后,应用程序返回到我不想要的索引页面。
这是我的代码(我使用 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');
});
}
}]);
索引.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>
也许它与现在必须调用插件的方式有关?
PhoneGap Build 上的 BarcodeScanner 插件今天将获得更新,使用它的应用程序需要更改其代码以使用 cordova.require:
老的:
window.plugins.barcodeScanner.scan(function(){ ... }, function(){ ... }, optionsObj)
新的:
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan(function (result) {...}, function (error) {...});
谢谢你的帮助。