gpt4 book ai didi

android - 无法让 Pdf417Scanner 作为插件与 Cordova/PhoneGap 一起工作

转载 作者:行者123 更新时间:2023-11-30 00:01:33 26 4
gpt4 key购买 nike

我正在尝试让 Pdf417Scanner 插件 ( https://github.com/PDF417/pdf417-phonegap ) 与 Cordova/PhoneGap 一起工作。

这是我到目前为止所做的。

  1. 使用 PhoneGap(UI 使用 Framework7)创建了一个新项目
  2. 添加插件,使用命令 phonegap plugin add pdf417-phonegap
  3. 使用命令 phonegap platform add android 添加了 Android 平台

调用 Pdf417Scanner 进行扫描的 JavaScript 代码 fragment 。大部分代码直接来自他们的 Github 项目文档。

$$(document).on('deviceready', function() {
console.log("Device is ready!");

$$('#scan').on('click', function () {
console.log("Inside the scan click");

var types = ["PDF417", "QR Code"];

/**
* Initiate scan with options
* NOTE: Some features are unavailable without a license
* Obtain your key at http://pdf417.mobi
*/
var options = {
beep : true, // Beep on
noDialog : true, // Skip confirm dialog after scan
uncertain : false, //Recommended
quietZone : false, //Recommended
highRes : false, //Recommended
inverseScanning: false,
frontFace : false
};

var licenseiOs = "sRwAAAEQbW9iaS5wZGY0MTcuZGVtbz/roBZ34ygXMQRMupTjSPXnoj0Mz1jPfk1iRX7f78Ux6a+pfXVyW0HCjPTxl5ocxgXWF66PTrtFUbJFCDUpyznreSWY4akvhvqVFfcTYgVEKjB+UqO6vPD5iIaUCaEYhF4dVmM=";

// This license is only valid for package name "mobi.pdf417.demo"
var licenseAndroid = "sRwAAAAQbW9iaS5wZGY0MTcuZGVtb2uCzTSwE5Pixw1pJL5UEN7nyXbOdXB61Ysy/sgAYt4SaB0T/g6JvisLn6HtB8LzLDmpFjULMxmB8iLsy3tFdHtMhLWOM6pr0tQmSLGyhrXfe6rVoHAxJtPrFEoCNTk4RjLltQ==";

cordova.plugins.pdf417Scanner.scan(
// Register the callback handler
function callback(scanningResult) {

// handle cancelled scanning
if (scanningResult.cancelled == true) {
myApp.alert("Cancelled!");
return;
}

// Obtain list of recognizer results
var resultList = scanningResult.resultList;

var resToShow = "";

// Iterate through all results
for (var i = 0; i < resultList.length; i++) {
// Get individual resilt
var recognizerResult = resultList[i];
resToShow += "(Result type: " + recognizerResult.resultType + ") <br>"
if (recognizerResult.resultType == "Barcode result") {
// handle Barcode scanning result
var raw = "";
if (typeof(recognizerResult.raw) != "undefined" && recognizerResult.raw != null) {
raw = " (raw: " + hex2a(recognizerResult.raw) + ")";
}
resToShow += "(Barcode type: " + recognizerResult.type + ")<br>"
+ "Data: " + recognizerResult.data + "<br>"
+ raw;
} else if (recognizerResult.resultType == "USDL result") {
// handle USDL parsing result

var fields = recognizerResult.fields;

resToShow += /** Personal information */
"USDL version: " + fields[kPPStandardVersionNumber] + "; " +
"Family name: " + fields[kPPCustomerFamilyName] + "; " +
"First name: " + fields[kPPCustomerFirstName] + "; " +
"Date of birth: " + fields[kPPDateOfBirth] + "; " +
"Sex: " + fields[kPPSex] + "; " +
"Eye color: " + fields[kPPEyeColor] + "; " +
"Height: " + fields[kPPHeight] + "; " +
"Street: " + fields[kPPAddressStreet] + "; " +
"City: " + fields[kPPAddressCity] + "; " +
"Jurisdiction: " + fields[kPPAddressJurisdictionCode] + "; " +
"Postal code: " + fields[kPPAddressPostalCode] + "; " +

/** License information */
"Issue date: " + fields[kPPDocumentIssueDate] + "; " +
"Expiration date: " + fields[kPPDocumentExpirationDate] + "; " +
"Issuer ID: " + fields[kPPIssuerIdentificationNumber] + "; " +
"Jurisdiction version: " + fields[kPPJurisdictionVersionNumber] + "; " +
"Vehicle class: " + fields[kPPJurisdictionVehicleClass] + "; " +
"Restrictions: " + fields[kPPJurisdictionRestrictionCodes] + "; " +
"Endorsments: " + fields[kPPJurisdictionEndorsementCodes] + "; " +
"Customer ID: " + fields[kPPCustomerIdNumber] + "; ";
}
resToShow += "<br><br>";
}
myApp.alert(resToShow);
},

// Register the error callback
function errorHandler(err) {
myApp.alert('Error: ' + err);
},

types, options, licenseiOs, licenseAndroid
);
});
});

它确实到达了 console.log("Inside the scan click"); 部分;但不确定它点击 cordova.plugins.pdf417Scanner.scan 后会发生什么 - 它只是不起作用。澄清一下,我直接在我的 Android 手机(使用 Android 7)上进行了测试。

有什么想法吗?有人用过这个库/插件吗?

最佳答案

问题是有人在 PDF417 团队之前在 NPM 上注册了 pdf417-phonegap,所以当你像这样安装插件时 phonegap plugin add pdf417-phonegap,你不会没有得到 https://github.com/PDF417/pdf417-phonegap,但是 https://github.com/alejonext/pdf417-phonegap,这是一个不同的插件并且它已被弃用。

要安装插件,请执行以下操作:

git clone https://github.com/PDF417/pdf417-phonegap
phonegap plugin add pdf417-phonegap/Pdf417/

从您当前的项目内部,或者您可以在外部进行并将 pdf417-phonegap/Pdf417/ 更改为您的克隆路径,但请确保您保持/Pdf417/部分原样该文件夹中的插件,而不是在根目录中。

我已经对此进行了测试并且扫描仪可以正常工作,我只是在 hex2a 上遇到错误,因为我没有该功能。

但你可以从他们的代码中挑选它https://github.com/PDF417/pdf417-phonegap/blob/master/www/js/index.js#L21-L27 :

function hex2a(hex) {
var str = '';
for (var i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
}
return str;
}

关于android - 无法让 Pdf417Scanner 作为插件与 Cordova/PhoneGap 一起工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49835107/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com