2
我目前正在嘗試使用Cordova條形碼掃描器插件開發混合應用程序Monaca。Monaca +條形碼掃描器回調問題
出於某種原因,掃描回調開始表現不正常。
立即掃描後,我得到一個同步消息對話框(「檢查同步目標文件...」),然後是「下載文件」對話框,最後是我要求的結果對話框。關閉我的結果對話框後,應用程序返回到索引頁面,我不想要。
這裏是我的代碼(我用溫泉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>
也許它現在的方式有關插件必須被稱爲?
的BarcodeScanner插件上的PhoneGap Build將在今天得到的最新情況,並應用在使用它需要改變他們的代碼使用cordova.require:
老:
window.plugins.barcodeScanner.scan(function(){ ... }, function(){ ... }, optionsObj)
新:
var scanner = cordova.require("cordova/plugin/BarcodeScanner");
scanner.scan(function (result) {...}, function (error) {...});
感謝您的幫助。