求助:webview方式集成Hbuilder的 5+sdk,在调用扫码api时,不能创建扫码控件,有朋友遇到过吗?
前端js代码执行无异常,代码如下:
// 扩展API加载完毕后调用onPlusReady回调函数
document.addEventListener("plusready", onPlusReady, false);
// 扩展API加载完毕,现在可以正常调用扩展API
function onPlusReady() {
//var e = document.getElementById("scan");
//e.removeAttribute("disabled");
//alert(plus.os.name);
startRecognize();
}
var scan = null;
function onmarked(type, result) {
var text = '未知: ';
switch (type) {
case plus.barcode.QR:
text = 'QR: ';
break;
case plus.barcode.EAN13:
text = 'EAN13: ';
break;
case plus.barcode.EAN8:
text = 'EAN8: ';
break;
}
alert(text + result);
}
function onerrored(e){
alert(e);
}
function startRecognize() {
try {
scan = new plus.barcode.Barcode('bcid');
scan.onmarked = onmarked;
scan.onerror = onerrored;
alert("scan=" + JSON.stringify(scan));
} catch (e) {
alert(e);
}
}
function startScan() {
try {
scan.start();
} catch (e) {
alert(e);
}
}
function cancelScan() {
try {
scan.cancel();
} catch (e) {
alert(e);
}
}
function setFlash() {
try {
scan.setFlash();
} catch (e) {
alert(e);
}
}
1 个回复
z***@foxmail.com
我也是跟踪到scan = new plus.barcode.Barcode('bcid')时报错:
TypeError: Cannot read property 'addEventListener' of null
at new d (<anonymous>:532:46)
at sweepOrScan (file:///storage/emulated/0/Android/data/ io.dcloud.HBuilder/ .HBuilder/apps/ HBuilder / www /business/create.html:562:21)
at file:///storage/emulated/0/Android/data/io.dcloud.HBuilder/.HBuilder/apps/HBuilder/www/business/ create.html:555:10
at Object.success (<anonymous>:2852:26)
at Object.plus.bridge.callbackFromNative (<anonymous>:389:66)
at <anonymous>:1:172
plus.barcode.scan正常
本机运行h5 demo的barcode完全正常