繁体   English   中英

PhoneGap条形码阅读器插件不起作用

[英]PhoneGap Barcode Reader Plugin not working

几天来我一直在尝试在我的应用程序中实现条形码读取器插件,但我没有任何运气。 当按下按钮时,它只是不执行任何操作。 多数民众赞成在我的JavaScript文件

    var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicitly call 'app.receivedEvent(...);'
onDeviceReady: function() {
    app.receivedEvent('deviceready');
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');

    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');

    console.log('Received Event: ' + id);
},
scan: function() {
    console.log('scanning');

    var scanner = cordova.require("cordova/plugins/BarcodeScanner");

    scanner.scan( function (result) { 

        alert("We got a barcode\n" + 
        "Result: " + result.text + "\n" + 
        "Format: " + result.format + "\n" + 
        "Cancelled: " + result.cancelled);  

       console.log("Scanner result: \n" +
            "text: " + result.text + "\n" +
            "format: " + result.format + "\n" +
            "cancelled: " + result.cancelled + "\n");
        document.getElementById("info").innerHTML = result.text;
        console.log(result);
        /*
        if (args.format == "QR_CODE") {
            window.plugins.childBrowser.showWebPage(args.text, { showLocationBar: false });
        }
        */

    }, function (error) { 
        console.log("Scanning failed: ", error); 
    } );
},
    encode: function() {
    var scanner = cordova.require("cordova/plugins/BarcodeScanner");

    scanner.encode(scanner.Encode.TEXT_TYPE, "http://www.nhl.com", function(success) {
        alert("encode success: " + success);
      }, function(fail) {
        alert("encoding failed: " + fail);
      }
    );

}};

多数民众赞成在index.html

    <html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="format-detection" content="telephone=no" />
    <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" />
    <script type="text/javascript" href="JQuery/jquery-1.12.3.min.js"></script>
    <script type="text/javascript" href="JQuery/jquery.mobile-1.4.5.js"></script>
    <link rel="stylesheet" type="text/css" href="JQuery/jquery.mobile-1.4.5.css" />

    <title>Barcode Scanner Demo</title>
</head>
<body>
    <div class="app">
        <h1>Apache Cordova</h1>
        <div id="deviceready" class="blink">
            <p class="event listening">Connecting to Device</p>
            <p class="event received">Device is Ready</p>
        </div>
        <p><a href="#" class="topcoat-button" id="scan">SCAN</a></p>
        <p><a href="#" class="topcoat-button" id="encode">ENCODE</a></p>
        <p id="info"></p>
        <h2>OPENING LINKS:</h2>
        <p><a href="#" class="topcoat-button" onclick="window.open('http://www.nhl.com', '_blank', 'location=yes');">InAppBrowser</a></p>
        <p><a href="#" class="topcoat-button" onclick="window.open('http://www.nhl.com', '_system', 'location=yes');">System Browser</a></p>
        <p><a href="#" class="topcoat-button" onclick="window.open('http://www.yahoo.com', '_self', 'location=yes');">This Webview</a></p>
        <p><a href="#" class="topcoat-button" onclick="window.plugins.childBrowser.showWebPage('http://www.nhl.com', {});">ChildBrowser</a></p>
    </div>
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="barcodescanner.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

我是否必须部署应用程序,还是可以仅使用PhoneGap for iOS提供的应用程序? 任何帮助将不胜感激。

我相信您需要将应用程序编译并安装在设备上或在模拟器中运行(假设您最好对设备进行条形码扫描,以便可以使用真实的相机)。 与iOS版PhoneGap应用程序不兼容的原因是,条形码扫描仪似乎不在您为该应用程序安装的插件列表中 ,这是:

<plugin name="cordova-plugin-battery-status" spec="~1.1.0" />
<plugin name="cordova-plugin-camera" spec="~2.0.0" />
<plugin name="cordova-plugin-console" spec="~1.0.1" />
<plugin name="cordova-plugin-contacts" spec="~2.0.0" />
<plugin name="cordova-plugin-device" spec="~1.0.1" />
<plugin name="cordova-plugin-device-motion" spec="~1.1.1" />
<plugin name="cordova-plugin-device-orientation" spec="~1.0.1" />
<plugin name="cordova-plugin-dialogs" spec="~1.1.1" />
<plugin name="cordova-plugin-file" spec="~4.0.0" />
<plugin name="cordova-plugin-file-transfer" spec="~1.3.0" />
<plugin name="cordova-plugin-geolocation" spec="~2.0.0" />
<plugin name="cordova-plugin-globalization" spec="~1.0.1" />
<plugin name="cordova-plugin-inappbrowser" spec="~1.1.1" />
<plugin name="cordova-plugin-media" spec="~2.0.0" />
<plugin name="cordova-plugin-media-capture" spec="~1.0.1" />
<plugin name="cordova-plugin-network-information" spec="~1.0.1" />
<plugin name="cordova-plugin-splashscreen" spec="~3.0.0" />
<plugin name="cordova-plugin-statusbar" spec="~2.0.0" />
<plugin name="cordova-plugin-vibration" spec="~2.0.0" />
<plugin name="phonegap-plugin-contentsync" spec="~1.2.3" />
<plugin name="cordova-plugin-whitelist" spec="~1.0.0" />
<plugin name="cordova-plugin-insomnia" spec="~4.0.1" />
<plugin name="cordova-plugin-ble-central" spec="~1.0.4" />
<plugin name="phonegap-plugin-push" spec="~1.6.3">

上面的列表来自PhoneGap Developer应用程序Github存储库config.xml文件。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM