我正在开发一个sencha触摸应用程序,具有phonegap和Android设备的目标。在应用程序中,可以选择扫描条形码。我用来实现条形码扫描。在这里,用户可以扫描条形码并返回到sencha屏幕。phonegap barcodescanner:如何多次扫描一次
根据我的要求,应用程序应允许用户一次扫描多个条形码,并且在用户完成扫描后应该返回到屏幕。我期待类似的方法,使用电话捕捉插件(允许用户同时拍摄多个图像/视频/声音,结果将在数组中)。
是否有办法同时进行多次扫描?
我正在开发一个sencha触摸应用程序,具有phonegap和Android设备的目标。在应用程序中,可以选择扫描条形码。我用来实现条形码扫描。在这里,用户可以扫描条形码并返回到sencha屏幕。phonegap barcodescanner:如何多次扫描一次
根据我的要求,应用程序应允许用户一次扫描多个条形码,并且在用户完成扫描后应该返回到屏幕。我期待类似的方法,使用电话捕捉插件(允许用户同时拍摄多个图像/视频/声音,结果将在数组中)。
是否有办法同时进行多次扫描?
该插件目前不支持该功能。您将不得不联系插件的作者进行修改或自己做。
我刚刚面临同样的问题,这里有一个解决方法,我想出了。
简而言之:只要代码成功返回,我将扫描的信息保存到数组中,然后立即重新开始扫描。
这是我用它来测试一个简单的流星应用在我的解决方法代码:
// 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);
}