2013-10-25 35 views
0

我試過barcodescanner.js samples,這是我需要Qrcode閱讀器的phonegap項目,提供的示例項目在xcode中工作正常。 iam試圖開發一個獨立的項目時出現問題。phonegap項目中的barcodescanner插件問題

  • 我config.xml文件有:

<plugin name="com.cordova.barcodeScanner" value="CDVBarcodeScanner" />

  • IAM使用:PhoneGap的2.7.0
  • 我已經包括barcodescanner.js和它的標籤正確。

我的代碼:

function onDeviceReady() 
       { 
        // do your thing! 
        navigator.notification.alert("PhoneGap is working"); 

        scanButton = document.getElementById("scan-button"); 
        resultSpan = document.getElementById("scan-result"); 

        scanButton.addEventListener("click", clickScan, false); 
        createButton.addEventListener("click", clickCreate, false); 

       } 
        function clickScan() { 
         alert("clickScan"); 
        window.plugins.barcodeScanner.scan(scannerSuccess, scannerFailure); 
       } 


       function scannerSuccess(result) { 
        console.log("scannerSuccess: result: " + result) 
        resultSpan.innerText = "success: " + JSON.stringify(result) 
       } 

       function scannerFailure(message) { 
        console.log("scannerFailure: message: " + message) 
        resultSpan.innerText = "failure: " + JSON.stringify(message) 
       } 

它是確定,直到警報; 「clickscan」,

之後沒有任何反應(什麼阻止我的window.plugins.barcodeScanner.scan(scannerSuccess, scannerFailure);工作)。

這是我的項目看起來像 - > enter image description here

蔭這種掙扎了兩天,我在SO檢查幾乎所有問題上「barcodescanner」標籤,did'nt解決了我的問題,需要你幫助..謝謝。

+0

你有沒有加入CDVBarcodeScanner.mm和斑馬線,所有功能於one.cpp/.H到CordovaLib /插件? 'alert(typeof window.plugins.barcodeScanner)'會在'clickScan'函數中顯示什麼? – pawel

+0

是啊...它都在那裏..警報(typeof window.plugins.barcodeScanner);沒有顯示任何東西 –

+0

@pawel:還有其他的東西需要配置嗎? (也看@我的項目樹)。 –

回答

1

在你的config.xml您有:

<plugin name="com.cordova.barcodeScanner" value="CDVBarcodeScanner" /> 

但是從你的問題鏈接的zip壓縮包barcodescanner.js它被稱爲是這樣的:

Cordova.exec(successWrapper, fail, "org.apache.cordova.barcodeScanner", "scan", options); 

所以嘗試改變線你的config.xml到

<plugin name="org.apache.cordova.barcodeScanner" value="CDVBarcodeScanner" /> 

經過更多的調查,它已經建立,barcodescan來自example .zip的ner.js是針對較早版本的Phonegap編寫的,與2.7不兼容。 Here's a version我有2.7和2.9使用,需要<plugin name="BarcodeScanner" value="CDVBarcodeScanner" />在config.xml文件中,可以這樣調用:

var scanner = cordova.require("cordova/plugin/barcodescanner"); 
scanner.scan(scannerSuccess, scannerFailure); 
+0

謝謝你,但它不幫助我。 –

+0

如果使用zip壓縮文件中的cordova-1.5.0.js而不是2.7,該怎麼辦?它可能使用不同的插件定義方法。源代碼看起來不像barcodescanner。我已經使用了Phone Phone 2.7和2.9。 – pawel

+0

非常感謝你!工作。 –

相關問題