2012-05-04 42 views
8

有沒有人設法讓PhoneGap的BarcodeScanning插件在PhoneGap 1.7.0上工作?iOS PhoneGap 1.7.0 +條碼掃描插件問題

條碼掃描插件:https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner

的問題是,插件是沒有得到設置時,其附加..

我碰到下面當我打電話「警報(window.plugins.barcodeScanner);」

「未定義」

我想在插件未能得到補充點隔離並會更新一次的問題我知道更多..提前

感謝的人誰可以提供幫助。 ..


更新答案如下:

回答

6

好了,等了一段時間,並使用twitter PhoneGap插件作爲例子,我設法讓它工作!

我用這個作爲我的方法的基礎,因爲可愛的人在twitter更新他們的插件與PhoneGap 1.7.0一起工作感謝上帝!

Twitter的PhoneGap的插件:https://github.com/phonegap/phonegap-plugins/blob/master/iOS/Twitter/js/TwitterPlugin.js

這裏是更新barcodescanner.js代碼:

var BarcodeScanner = function(){}; 

BarcodeScanner.prototype.isBarcodeScannerAvailable = function(response){ 
    cordova.exec(response, null, "BarcodeScannerPlugin", "isBarcodeScannerAvailable", []); 
}; 

BarcodeScanner.prototype.isBarcodeScannerSetup = function(response){ 
    cordova.exec(response, null, "BarcodeScannerPlugin", "isBarcodeScannerSetup", []); 
}; 

//------------------------------------------------------------------- 
BarcodeScanner.Encode = { 
TEXT_TYPE:  "TEXT_TYPE", 
EMAIL_TYPE: "EMAIL_TYPE", 
PHONE_TYPE: "PHONE_TYPE", 
SMS_TYPE:  "SMS_TYPE", 
CONTACT_TYPE: "CONTACT_TYPE", 
LOCATION_TYPE: "LOCATION_TYPE" 
} 

//------------------------------------------------------------------- 
BarcodeScanner.prototype.scan = function(success, fail, options) { 
    function successWrapper(result) { 
     result.cancelled = (result.cancelled == 1) 
     success.call(null, result) 
    } 

    if (!fail) { fail = function() {}} 

    if (typeof fail != "function") { 
     console.log("BarcodeScanner.scan failure: failure parameter not a function") 
     return 
    } 

    if (typeof success != "function") { 
     fail("success callback parameter must be a function") 
     return 
    } 

    if (null == options) 
     options = [] 

     return PhoneGap.exec(successWrapper, fail, "com.cordova.barcodeScanner", "scan", options) 
     } 

//------------------------------------------------------------------- 
BarcodeScanner.prototype.encode = function(type, data, success, fail, options) { 
    if (!fail) { fail = function() {}} 

    if (typeof fail != "function") { 
     console.log("BarcodeScanner.scan failure: failure parameter not a function") 
     return 
    } 

    if (typeof success != "function") { 
     fail("success callback parameter must be a function") 
     return 
    } 

    return PhoneGap.exec(success, fail, "com.cordova.barcodeScanner", "encode", [{type: type, data: data, options: options}]) 
} 

cordova.addConstructor(function() { 

         /* shim to work in 1.5 and 1.6 */ 
         if (!window.Cordova) { 
         window.Cordova = cordova; 
         }; 


         if(!window.plugins) window.plugins = {}; 
         window.plugins.barcodeScanner = new BarcodeScanner(); 
         }); 
+0

感謝您指出新名稱:com.cordova.barcodeScanner。你是怎麼找到這個的?
我在Cordova.plist中更改了它,至少它創建了掃描儀對象。請注意,21小時的舊文件仍然引用org.apache.cordova。barcodeScanner在https://github.com/phonegap/phonegap-plugins/blob/master/iOS/BarcodeScanner/barcodescanner.js。 – GeorgeW

+1

@damien墨菲 - 感謝隊友,終於在3天的頭髮拉它的作品...;) –

11

優秀,

現在插件再次工作。
一個問題是該插件的文檔仍然說Cordova.plist中的密鑰應該是org.apache.cordova.barcodeScanner,但現在應該是com.cordova.barcodeScanner

3

我只是說barcodescanner科爾多瓦2.3 - 這是

複製後相當簡單您只需將以下行添加到config.xml所需的文件

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

在情況下,這有助於任何: https://github.com/zeroasterisk/PhoneGap-BarcodeScanner-Example-iOS

具體來說:

安裝了插件(在路徑少數),但保持其工作的一個。實現了一個基本的JS掃描器代碼來演示功能:加載時自動運行,錯誤時自動重新加載,成功/失敗/取消提醒。

注意:關於barcodescanner.js和index.js的註釋都提到了我對定義/要求對象路徑的定製。經過幾次排列後,我無法獲得演示/示例路徑的工作。