安卓更新方式
androidUpdateMethod() {
// this.downloadUrl 下载地址,后端返回
var dtask = plus.downloader.createDownload(this.downloadUrl, {}, function(d, status) {
// 下载完成
if (status == 200) {
plus.runtime.install(plus.io.convertLocalFileSystemURL(d.filename), {}, {}, function(
error) {
uni.showToast({
title: '安装失败',
duration: 2000
});
})
} else {
uni.showToast({
title: '更新失败',
duration: 2000
});
}
});
dtask.addEventListener("statechanged", (task) => {
// console.log(task.state)
switch (task.state) {
case 1: {
console.log('开始下载');
this.download = true // 开始下载
this.updateMask = true // 开启遮罩层
break;
}
case 2: {
console.log('链接到服务器...');
this.download = true
this.updateMask = true
break;
}
case 3: {
let progressVal = 0; //写成局部变量试试
progressVal = (task.downloadedSize / task.totalSize) * 100;
this.percent = parseInt(progressVal) // 下载进度条
break;
}
case 4: {
cnosole.log('监听下载完成');
this.download = false
this.updateMask = false
}
}
}, false);
dtask.start();
},
ios更新方式
iosIpdatemethod() {
uni.showModal({
content: '当前有新版本更新,是否前往更新?',
success: res => {
if (res.confirm) {
plus.runtime.openURL(this.downloadUrl);
}
}
})
},