【问题标题】:iOS PhoneGap 1.7.0 + Barcode Scanning Plugin issueiOS PhoneGap 1.7.0 + 条码扫描插件问题
【发布时间】:2012-05-04 13:54:16
【问题描述】:

有没有人设法让 PhoneGap 的 BarcodeScanning 插件在 PhoneGap 1.7.0 上工作?

条码扫描插件:https://github.com/phonegap/phonegap-plugins/tree/master/iOS/BarcodeScanner

问题是插件在添加时没有设置..

当我调用“alert(window.plugins.barcodeScanner);”时,我得到以下信息

“未定义”

我正在尝试找出无法添加插件的点,并在我了解更多信息后更新问题..

提前感谢任何可以提供帮助的人...


以下更新答案:

【问题讨论】:

    标签: ios cordova barcode-scanner phonegap-plugins


    【解决方案1】:

    非常好,

    该插件现在可以再次使用。
    一个问题是插件的文档仍然说Cordova.plist 中的密钥应该是org.apache.cordova.barcodeScanner,但现在很明显它应该是com.cordova.barcodeScanner

    【讨论】:

      【解决方案2】:

      好吧,经过一番摸索,并以 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();
                             });
      

      【讨论】:

      • 感谢您指出新名称:com.cordova.barcodeScanner。你是怎么发现的?
        我在 Cordova.plist 中更改了它,至少它创建了扫描仪对象。请注意,21 小时前的文件仍然在 github.com/phonegap/phonegap-plugins/blob/master/iOS/… 引用 org.apache.cordova.barcodeScanner。
      • @damien murphy - 谢谢伙计,在拉了 3 天头发后,它终于起作用了……;)
      【解决方案3】:

      我刚刚将barcodescanner 添加到cordova 2.3 - 这很简单

      复制必要的文件后,您只需将以下行添加到 config.xml

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

      【讨论】:

        【解决方案4】:

        如果这对任何人都有帮助: https://github.com/zeroasterisk/PhoneGap-BarcodeScanner-Example-iOS

        具体来说:

        安装了插件(在少数几个路径中),但保留了一个有效的。实现了一个基本的 JS 扫描器代码来演示功能:加载时自动运行,错误时自动重新加载,成功/失败/取消警报。

        注意:barcodescanner.js 和 index.js 上的 cmets 都提到了我对定义/要求对象路径的自定义。经过几次排列后,我无法让演示/示例路径正常工作。

        【讨论】:

          猜你喜欢
          • 2012-07-04
          • 2014-07-18
          • 1970-01-01
          • 1970-01-01
          • 2013-08-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多