2025-03-JS-SDK-PDA/common/CheckUpdate.js
2025-03-11 09:45:29 +08:00

39 lines
1.3 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 下载wgt文件
function downWgt(urlRoot,version) {
plus.nativeUI.showWaiting("下载应用安装包...");//进度提示
plus.downloader.createDownload(urlRoot,{ //创建下载任务
filename: "_downloads/update/"+ new Date().getTime() + '/'//下载后的文件存放路径,加个时间,这样生成的热更新包就不会冲突了
}, function(d, status) {
//d为下载的文件对象
if (status == 200) {
installWgt(d.filename,version); // 安装应用包
} else {
plus.nativeUI.alert("下载应用更新包失败!");
}
plus.nativeUI.closeWaiting();//使用了showWaiting必须关闭这个等待进度条
}).start();//开始下载
}
// 更新应用资源包
function installWgt(path,version) {
plus.nativeUI.showWaiting("安装文件中...");
plus.runtime.install(path, {
force: true
}, function() {
plus.nativeUI.closeWaiting();//使用了showWaiting必须关闭这个等待进度条
plus.nativeUI.alert("应用资源更新完成!", function() {
uni.setStorageSync('appVersion',version);
console.log("写入版本号:");
console.log(version);
plus.runtime.restart();//重启应用
});
}, function(e) {
plus.nativeUI.closeWaiting();//关闭进度条
plus.nativeUI.alert("安装更新包失败[" + e.code + "]" + e.message);
});
}
export {
installWgt,
downWgt
}