versionNum() {
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
console.log(wgtinfo.version); //版本号
updateEdition({ //后端接口查看是否需要更新
version: wgtinfo.version,
type: 'driver'
}).then((res) => {
console.log(res.data.code)
if (res.data.code== 202) {
uni.showToast({
title: res.data.msg,
icon: 'none'
});
} else {
this.userUrl = res.data.data.driver_url
console.log(res.data.data.driver_url)
uni.showModal({
title: "发现新版本,请确认更新",
content:res.data.data.driver_update_content,
showCancel: false,
success: (res) => {
if (res.confirm) {
//设置 最新版本apk的下载链接
var downloadApkUrl = 'https:'+this.userUrl;
var dtask = plus.downloader.createDownload(
downloadApkUrl, {},
function(d, status) {
// 下载完成
if (status == 200) {
plus.runtime.install(plus.io
.convertLocalFileSystemURL(
d.filename), {}, {},
function(error) {
uni.showToast({
title: '安装失败',
duration: 1500
});
})
} else {
uni.showToast({
title: '更新失败',
duration: 1500
});
}
});
try {
dtask.start(); // 开启下载的任务
var prg = 0;
var showLoading = plus.nativeUI.showWaiting(
"正在下载"); //创建一个showWaiting对象
dtask.addEventListener('statechanged', function(
task,
status
) {
// 给下载任务设置一个监听 并根据状态 做操作
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;
}
});
} catch (err) {
plus.nativeUI.closeWaiting();
uni.showToast({
title: '更新失败-03',
mask: false,
duration: 1500
});
}
} else if (res.cancel) {}
}
})
}
})
})
},
07-04
716
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
07-04
2071
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-24