phonegap-plugin-barcodescanner, type PDF417 bar-codes using ionic

两盒软妹~` 提交于 2019-12-11 05:58:06

问题


I am fairly new to Ionic development and thus far has not run into too many problems. However, I am stuck on trying to get PDF417 type bar-codes to scan (using phonegap-plugin-barcodescanner), despite the documentation suggesting that they are supported via pass the "PDF_417" parameter in the "formats" option. Note: the scanning works on other codes such as QR_CODE, EAN_13 - So the code is mostly right. I don't think that the options list after the error function is being processed.

  $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
  });

Any help, suggestion and or pointers will be gratefully received.

Thank you in advance, Harold Clements


回答1:


Yes, you have badly written the code, you have an error in the $cordovaBarcodeScanner.scan() funtion, because it is a promise, therefore it returns two callbackFuntion from .them method

q.resolve(result);

q.reject(err);

$CordovaBarcodeScanner ia a factory that returns two functiosns

A function with an input argument

scan: function (config) {

and the secondone with two input arguments

encode: function (type, data) {}

bouth are promise functios

so the correct way to make the request is:

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);
    });
  */

in your html

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

Reviewing the ios library, it only contains the following types of formats, so it does not work for iOS. If you find some method to scan PDF417 in ios using IONIC, you can share it!

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;

I hope it will be useful for everyone



来源:https://stackoverflow.com/questions/40549782/phonegap-plugin-barcodescanner-type-pdf417-bar-codes-using-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!