// 取得版本号
plus.runtime.getProperty(plus.runtime.appid, function(wgtinfo) {
that.ver = wgtinfo.version
// console.log(that.ver, '当前版本号');
});
that.http.get('http://wdt.cn-sh2.ufileos.com/n/paage.json').then(res => {
uni.request({
url: res.data.url + "/api/portal/index/version", //请求更新地址
success: res => {
// return
var data = res.data.data;
// console.log(data)
// console.log(data.version)
// console.log(that.ver == data.version)
// console.log(that.ver)
if (that.ver != data.version) {
that.wgtUrl = data.android; //保存下载地址
that.wgtipurl = data.ios;
// console.log(that.wgtUrl)
uni.showModal({
title: '发现新版本',
content: '确认下载更新',
success: function(e) {
if (e.confirm) {
if (plus.os.name.toLowerCase() == 'ios') {
// 跳转到下载页面
plus.runtime.openURL(data.ios)
} else {
console.log(that.wgtUrl)
var dtask = plus.downloader.createDownload(
that.wgtUrl, {},
function(d, status) {
console.log(status, 333333333333333333333)
uni.showToast({
title: '下载完成',
mask: false,
duration: 1500
});
});
try {
dtask.start(); // 开启下载的任务
var prg = 0;
var showLoading = plus.nativeUI.showWaiting("正在下载"); //创建一个showWaiting对象
dtask.addEventListener('statechanged', function(
task,
status
) {
console.log(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();
//下载完成
plus.runtime.install(plus.io.convertLocalFileSystemURL(task.filename), //安装APP
{
force: true
},
function() {
uni.showToast({
title: '安装成功',
icon: 'none',
mask: false,
duration: 1500
})
plus.runtime.restart();
},
function() {
uni.showToast({
title: '安装失败',
icon: 'none',
mask: false,
duration: 1500
})
});
break;
}
});
} catch (err) {
plus.nativeUI.closeWaiting();
uni.showToast({
title: '更新失败',
mask: false,
icon: 'none',
duration: 1500
});
}
}
} else {
//取消
}
}
});
} else {
// uni.showModal({
// title: '提示',
// content: '已是最新版本',
// showCancel: false
// });
}
},
})
})
动态获取和域名更新
最新推荐文章于 2024-06-07 07:59:24 发布