我是Ionic2的新手,但在网络开发方面有经验。现在只是在学习新的平台。
因此,我尝试集成Anyline https://github.com/Anyline/anyline-ocr-cordova-module。
但是我失败了,在我看来,这个插件是用Javascript写的,和TS不兼容,但我不确定……
有没有人能帮上忙?
谢谢,
本
发布于 2017-03-24 10:41:12
不确定你是否还需要帮助,但对于那些正在寻找可行解决方案的人来说,这里是我的:
将Anyline插件添加到项目cordova plugin add io-anyline-cordova中
2-创建一个新文件ionic g provider anyline
3-将此代码添加到anyline.ts文件中:
export class OCR {
constructor() {
if (anylineScan === undefined) {
var anylineScan = {};
}
}
anylineScan = {
onResult: function (result) {
console.log("MRZ result: " + JSON.stringify(result));
//do what you want here with the result
},
onError: function (error) {
console.log("scanning error");
},
scan: function () {
var licenseKey = "enterYourLicenceKeyHere";
try {
(<any>window).cordova.exec(this.onResult, this.onError, "AnylineSDK", "OCR", [licenseKey, {
"captureResolution":"1080p",
//your other config setting here
}]);
}
catch (e){
console.log("Cannot open scan view: ERROR occurred");
}
}
}4-将文件引用添加到app.module.ts文件
import { OCR } from '../yourFolderName/anyline';
...
providers: [Storage, OCR]5-在page.ts文件中添加以下调用:
this.anyline.anylineScan.scan();重要!在浏览器中不能工作,请确保运行ionic platform add ios (或安卓)并在设备上运行该应用程序。
这应该管用!
祝好运和愉快的编码:-)
https://stackoverflow.com/questions/41832585
复制相似问题