【问题标题】:phonegap-plugin-barcodescanner, type PDF417 bar-codes using ionicphonegap-plugin-barcodescanner,使用 ionic 输入 PDF417 条形码
【发布时间】:2016-11-11 14:11:56
【问题描述】:

我对 Ionic 开发相当陌生,到目前为止还没有遇到太多问题。但是,尽管文档建议通过“格式”选项中的“PDF_417”参数来支持它们,但我仍然试图让 PDF417 类型的条形码进行扫描(使用 phonegap-plugin-barcodescanner)。注意:扫描适用于其他代码,例如 QR_CODE、EAN_13 - 所以代码大部分是正确的。我不认为正在处理错误函数之后的选项列表。

  $cordovaBarcodeScanner.scan().then(function(imageData) {

    $scope.si_data_display = imageData.text;
    console.log("app.js :: .controller - MainCtrl :: scan_barcode :: text : " + imageData.text);
    console.log("app.js :: .controller - MainCtrl :: scan_barcode :: format : " + imageData.format);
    console.log("app.js :: .controller - MainCtrl :: scan_barcode :: cancelled  : " + imageData.cancelled);

  }, function(error) {
    //TODO: better error handling...
    alert("Error with BarcodeScanner" + error);
  },
  { //I DONT THINK THIS IS WORKING!
    "preferFrontCamera" : true, // iOS and Android
    "showFlipCameraButton" : true, // iOS and Android
    "prompt" : "zzzzzzzzzzzz", // supported on Android only
    "formats" : "PDF_417", // default: all but PDF_417 and RSS_EXPANDED
  });

我们将不胜感激地收到任何帮助、建议和/或指点。

提前谢谢你, 哈罗德克莱门茨

【问题讨论】:

  • 你测试的设备,根据文档它只支持Android,WinPhone。我认为它只是Beta版本,所以需要下载源代码而不是通过npm直接安装。
  • 感谢您的回复 - 抱歉,应该在原帖中提到...它是 Android(三星 S6)。
  • 你可以试试这个插件:github.com/PDF417/pdf417-phonegap
  • 感谢您的建议。最后,我用所有可用的格式对插件进行了硬编码,效果很好。
  • 您应该在答案中添加您为下一个可怜的家伙做了什么。干杯。

标签: cordova ionic-framework pdf417


【解决方案1】:

是的,你写的代码很糟糕,你在 $cordovaBarcodeScanner.scan() 函数中有一个错误,因为它是一个承诺,因此它从 .them 方法返回两个 callbackFuntion

q.resolve(结果);

q.reject(err);

$CordovaBarcodeScanner 是一个返回两个函数的工厂

带有输入参数的函数

扫描:功能(配置){

第二个有两个输入参数

编码:函数(类型、数据){}

都是承诺函数

所以提出请求的正确方法是:

document.addEventListener("deviceready", function () {
$scope.scan= function () {

  $cordovaBarcodeScanner
    .scan({ //I KNOW THIS IS GOOD!
           "preferFrontCamera" : true, // iOS and Android
           "showFlipCameraButton" : true, // iOS and Android
           "prompt" : "zzzzzzzzzzzz", // supported on Android only
           "formats" : "PDF_417"  //NO ',' in the last element
          })
    .then(function (imageData) {
      $scope.si_data_display = imageData.text;
      alert(JSON.stringify(imageData));
    }, function (error) {
      $scope.result=" :( intentalo de nuevo. Ocurrio un Error"
      alert(Error);
    });
}
  /*
    try to use, but inject in your controller
    $ionicPlatform.ready(function() {
      $cordovaBarcodeScanner.scan().then(success, error);
    });
  */

在你的 html 中

<button class="button" ng-click="scan()">Escanear</button>

查看ios库,它只包含以下几种格式,因此不适用于iOS。如果你找到一些使用IONIC在ios中扫描PDF417的方法,你可以分享一下!

typedef enum BarcodeFormat {
    BarcodeFormat_None = 0,
    BarcodeFormat_QR_CODE,
    BarcodeFormat_DATA_MATRIX,
    BarcodeFormat_UPC_E,
    BarcodeFormat_UPC_A,
    BarcodeFormat_EAN_8,
    BarcodeFormat_EAN_13,
    BarcodeFormat_CODE_128,
    BarcodeFormat_CODE_39,
    BarcodeFormat_ITF
} BarcodeFormat;

希望对大家有用

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多