我从 Phonegap 开始,我也在我的 iPhone 中使用 Phonegap 开发者应用程序来测试应用程序,所以我尝试了我找到的每个代码示例。然而,他们都没有工作。使用 Phonegap developer 测试条码扫描器时是否有问题?
这是我的 index.html:
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="msapplication-tap-highlight" content="no" />
<!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>qr app</title>
</head>
<body>
<p>
<button id="startScan">Start Scan</button>
</p>
<div id="results"></div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
这是我的 index.js:
var resultDiv;
document.addEventListener("deviceready", init, false);
function init() {
document.querySelector("#startScan").addEventListener("touchend", startScan, false);
resultDiv = document.querySelector("#results");
}
function startScan() {
cordova.plugins.barcodeScanner.scan(
function (result) {
var s = "Result: " + result.text + "<br/>" +
"Format: " + result.format + "<br/>" +
"Cancelled: " + result.cancelled;
resultDiv.innerHTML = s;
},
function (error) {
alert("Scanning failed: " + error);
}
);
}
我确实通过 Phonegap 添加了插件plugin add phonegap-plugin-barcodescanner
,然后运行phonegap serve
,在浏览器或 Phonegap 开发人员应用程序中打开它后,当我按下按钮时没有任何反应。