安装
npm 安装
npm i h5plus-hotfix -S
script加载
<script src="hotfix-bs.js"></script>
使用
hotfix({
url: updateUrl,
before(data) {
// 确认安装
return new Promise(resolve => {
plus.nativeUI.confirm(data.title, (selected) => {
if (selected.index === 0) {
plus.nativeUI.showWaiting("下载更新文件...");
resolve(data);
}
}, {
title: data.description,
buttons: ["确认更新", "取消"],
verticalAlign: "bottom"
});
});
},
success() {
console.log('安装成功')
plus.runtime.restart(); // 重启app
plus.nativeUI.closeWaiting();
},
error(e) {
// 错误显示
plus.nativeUI.closeWaiting();
console.log("安装wgt文件失败[" + e.code + "]:" + e.message);
plus.nativeUI.alert("安装wgt文件失败[" + e.code + "]:" + e.message);
},
onProgress(p) {
console.log(p) // 下载进度
}
});