详细问题描述
安卓 使用 plus.barcode.Barcode 进行扫码,当识别到数据时闪退
调试正常,打包发布后安装出现问题,ios正常。
重现步骤
调试正常,打包发布后安装出现问题,ios正常。
运行环境
[系统版本] 华为4.0
[浏览器版本]
[IDE版本] wap2app 在线打包
[mui版本]Mui v3.5.0
附件
[代码片段]
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<meta name="HandheldFriendly" content="true" />
<meta name="MobileOptimized" content="320" />
<title>Hello H5+</title>
<script type="text/javascript" src="js/common.js"></script>
<script src="../js/jquery.min.js"></script>
<script type="text/javascript">
var ws = null, wo = null;
var scan = null, domready = false;
// H5 plus事件处理
function plusReady() {
if (ws || !window.plus || !domready) {
return;
}
// 获取窗口对象
ws = plus.webview.currentWebview();
wo = ws.opener();
// 开始扫描
if (window.parent.plus.device.vendor == "Apple") {
ws.addEventListener('show', function () {
scan = new plus.barcode.Barcode('bcid', [plus.barcode.CODE39, plus.barcode.CODE128]);
scan.onmarked = onmarked;
scan.start({ conserve: true, filename: '_doc/barcode/' });
}, false);
}
else {
ws.addEventListener('show', function () {
scan = new plus.barcode.Barcode('bcid', [plus.barcode.CODE39, plus.barcode.CODE128]);
//scan.onmarked = onmarked;
//scan.start({ conserve: true, filename: '_doc/barcode/' });
}, false);
}
// 显示页面并关闭等待框
ws.show('pop-in');
//wo.evalJS('closeWaiting()');
}
if (window.plus) {
plusReady();
} else {
document.addEventListener('plusready', plusReady, false);
}
// 监听DOMContentLoaded事件
document.addEventListener('DOMContentLoaded', function () {
domready = true;
plusReady();
}, false);
// 二维码扫描成功
function onmarked(type, result, file) {
//plus.nativeUI.alert('扫描成功');
if (window.parent.plus.device.vendor == "Apple") {
plus.nativeUI.toast("扫描成功");
console.log("onmarked");
result = result.replace(/\n/g, '').replace(/"/g, '');
console.log(result);
console.log(ws.BackJS.replace('{result}', result));
wo.evalJS(ws.BackJS.replace('{result}', result));
plus.webview.close(ws);
}
else {
plus.nativeUI.toast("扫描成功222");
}
}
// 从相册中选择二维码图片
function scanPicture() {
plus.gallery.pick(function (path) {
plus.barcode.scan(path, onmarked, function (error) {
//plus.nativeUI.alert('无法识别此图片');
plus.nativeUI.showWaiting("识别中...");
console.log("Capture image success: " + path);
plus.io.resolveLocalFileSystemURL(path, function (entry) {
entry.file(function (file) {
var fr = new plus.io.FileReader();
fr.onload = function (e) {
var data = e.target.result;
var image = new Image();
image.onload = function () {
var width = image.width;
var height = image.height;
console.log("image.onload" + width + "," + height);
if (image.width > 720) {
width = 720;
height = 720 * image.height / image.width;
}
console.log("image.onload" + width + "," + height);
var canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
var ctx = canvas.getContext("2d");
ctx.drawImage(image, 0, 0, width, height);
data = canvas.toDataURL("image/jpeg", 1);
setTimeout(function () {
$.post("http://" + window.location.host + "/SysManage/Attachment/UploadImg", { data: data, temp: "111" }, function (rs) {
console.log(rs.isSuccess);
if (rs.isSuccess) {
console.log(rs.Data.ID);
//解析条码里面的运单号
$.get("http://" + window.location.host + "/SysManage/BarCode/Read?AttaID=" + rs.Data.ID).done(function (rs) {
var Data = JSON.parse(rs.Data);
if (rs.isSuccess && Data.status == "0") {
var waybills = "";
for (i in Data.result) {
if (Data.result[i].number.length == 10) {
if (waybills.length > 0) waybills += ",";
waybills += Data.result[i].number;
}
}
plus.nativeUI.closeWaiting();
wo.evalJS(ws.BackJS.replace('{result}', waybills));
plus.webview.close(ws);
}
else {
plus.nativeUI.closeWaiting();
plus.nativeUI.alert('无法识别此图片');
}
});
}
else {
plus.nativeUI.alert(rs.Message);
}
})
.error(function () {
plus.nativeUI.alert("error");
})
}, 500);
};
image.src = data;
};
fr.readAsDataURL(file);
console.log("readAsDataURL");
});
}, function (e) {
plus.nativeUI.alert("Resolve file URL failed: " + e.message);
});
}, [plus.barcode.CODE39, plus.barcode.CODE128]);
}, function (err) {
console.log('Failed: ' + err.message);
});
}
</script>
<link rel="stylesheet" href="css/common.css" type="text/css" charset="utf-8" />
<style type="text/css">
#bcid { width: 100%; position: absolute; top: 0px; bottom: 44px; text-align: center; }
.tip { color: #FFFFFF; font-weight: bold; text-shadow: 0px -1px #103E5C; }
footer { width: 100%; height: 44px; position: absolute; bottom: 0px; line-height: 44px; text-align: center; color: #FFF; }
.fbt { width: 50%; height: 100%; background-color: #FFCC33; float: left; }
.fbt:active { -webkit-box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5); box-shadow: inset 0 3px 5px rgba(0, 0, 0, 0.5); }
</style>
</head>
<body style="background-color: #000000;">
<div id="bcid">
<div style="height:40%"></div>
<p class="tip">...载入中...</p>
</div>
<footer>
<div class="fbt" onclick="plus.webview.close(ws);">取 消</div>
<div class="fbt" onclick="scanPicture()">从相册选择</div>
</footer>
</body>
</html>
联系方式
[QQ] 13461380
[电话] 18858005868
格创网络
勾选了也不行啊 。
2018-06-11 10:34