2016-05-09 2 views
0

Я пытался внедрить плагин для чтения штрих-кода в своем приложении на пару дней, и мне не повезло. он просто ничего не делает, когда нажимается кнопка. Вот моего файл JavaScriptPhoneGap Barcode Reader Plugin не работает

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 для прошивки? Любая помощь будет принята с благодарностью.

ответ

0

Я считаю, что вам нужно будет скомпилировать и установить приложение на устройство или запустить в симуляторе (если вы хотите, чтобы сканирование штрих-кода было лучше всего, чтобы вы могли использовать настоящую камеру). Причина этого не работает с PhoneGap для прошивкой приложение для разработчиков является то, что сканер штрих-кода не появляется, чтобы быть на list of plugins, установленной в том, что приложение для вас, что:

<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 Github repo, файл config.xml.

+0

Возможно, это проблема, я подумал, что приложение PhoneGap развертывает приложение с установленными плагинами, спасибо, я попробую симулятор и/или телефон и вернусь! – VoodooTech

Смежные вопросы