QR扫描仪不适用于phonegap

时间:2016-07-20 19:46:28

标签: cordova phonegap-plugins barcode-scanner phonegap-cli phonegap-developer-app

我开始使用Phonegap,我也在我的iPhone中使用Phonegap开发者应用程序来测试应用程序,所以我尝试了我找到的每个代码示例。但是,它们都没有奏效。使用Phonegap开发人员测试条形码扫描器时是否存在问题?

这是我的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开发者应用程序中打开它后,按下按钮时没有任何反应。

0 个答案:

没有答案