我正在开发一个具有 phonegap 和针对 android 设备的 sencha touch 应用程序。在应用程序中,有一个扫描条形码的选项。我已使用此链接来实现条形码扫描。在这里,用户可以扫描条形码并返回煎茶屏幕。
根据我的要求,该应用程序应允许用户一次扫描多个条形码,并且在用户完成扫描后应返回屏幕。我期待使用phonegap捕获插件的类似方法(允许用户同时拍摄多个图像/视频/声音,结果将在数组中)。
有没有办法同时进行多次扫描。
我刚刚遇到了同样的问题,这是我想出的解决方法。
简而言之:每当成功返回代码时,我都会将扫描的信息保存到数组中,然后立即重新启动扫描。
这是我用来在一个简单的流星应用程序中测试我的解决方法的代码:
// list to collect successfully scans
var scanned_list=[];
// callback function that will be executed everytime barcodescanner.scan ends without error
scannedOneItem = function (result) {
// user cancelled the scan: now check if we have something scanned already or not:
if(result.cancelled){
if(scanned_list.length>0){
// no items scanned, user cancelled
alert("Scanned items: " + scanned_list.length);
}
else{
alert("Scanned canceled");
}
}
// a item was scanned successfully - add it to list, and restart barcodescanner
else{
scanned_list.append(result.text);
cordova.plugins.barcodeScanner.scan(
scannedOneItem,
function (error) {
alert("Scanning failed: " + error);
}
);
}
}
Template.barcode_scanner.events({
'click button': function () {
// start scanning when button is pressed:
cordova.plugins.barcodeScanner.scan(
scannedOneItem,
function (error) {
alert("Scanning failed: " + error);
}
);
}
});
该插件当前不支持此功能。您必须联系插件的作者进行修改或自己进行修改。
它已使用上面的解决方案@80prozet工作,您必须考虑使用本机后退按钮取消扫描:
async scan_products (){
const results = await this.barcode.scan();
if(results.cancelled) {
this.platform.ready().then(() => {
// catch the native back button to cancel scan
this.platform.registerBackButtonAction(function(event){
event.preventDefault();
event.stopPropagation();
console.log("Scanned Canceled");
});
});
}
// a item was scanned successfully - add it to list, and restart barcodescanner //
else{
this.scanned_products.push(results.text);
this.scan_products();
}
console.log(results);
}