| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- // 下载并安装最新的APP版本
- function downloadApp(appUrl) {
- // 下载最新版本APP
- var dtask = plus.downloader.createDownload(
- appUrl,
- {
- method: "GET",
- },
- (d, status) => {
- if (status == 200) {
- plus.runtime.install(
- plus.io.convertLocalFileSystemURL(d.filename),
- {},
- {},
- () => {
- uni.showToast({
- title: "安装失败",
- duration: 1500,
- icon: "none",
- });
- },
- );
- } else {
- plus.nativeUI.alert("安装失败,请稍候重试: " + status);
- }
- },
- );
- dtask.start();
- var prg = 0;
- var showLoading = plus.nativeUI.showWaiting("正在下载");
- dtask.addEventListener("statechanged", function (task) {
- switch (task.state) {
- case 1:
- showLoading.setTitle("正在下载");
- break;
- case 2:
- showLoading.setTitle("已连接到服务器");
- break;
- case 3:
- prg = parseInt(
- (parseFloat(task.downloadedSize) / parseFloat(task.totalSize)) * 100,
- );
- showLoading.setTitle("版本更新,正在下载" + prg + "% ");
- break;
- case 4:
- plus.nativeUI.closeWaiting();
- break;
- }
- });
- }
- export { downloadApp };
|