/**
* 判断是否需要更新软件
*/
isUpdate() {
uni.request({
url: this.cxUrl + "versionInfo/getLastAPPVersion",
success: (res) => {
var newVer = res.data.data.versionName;
var wgtVer;
plus.runtime.getProperty(plus.runtime.appid,function(inf){
wgtVer=inf.version;
wgtVer= wgtVer.replace(".", '').replace(".", '');
newVer = newVer.replace(".", '').replace(".", '');
if (wgtVer < newVer) {
plus.nativeUI.confirm("有新功能哦!要不要尝试一下", function(e) {
var sure = (e.index == 0) ? "Yes" : "No";
if (sure == 'Yes') {
that.checkPlatform(res);
}
})
} else {
//plus.nativeUI.alert("暂无新版本!");
}
});
}
})
},
checkPlatform(res){
console.log("==="+res.data.data.versionNo)
var update_url;
//检测客户端平台是安卓还是ios return:ios、android
var platform = uni.getSystemInfoSync().platform;
switch (platform){
case 'android':
update_url=res.data.data.androidPackageUrl;
break;
case 'ios':
update_url=res.data.data.iosPackageUrl;
break;
default:
break;
}
//判断是升级包还是安装包
if(res.data.data.versionNo=="0"){
//console.log("安装包");
that.upgradeType = 'pkg'
that.upgradeUrl = update_url
}else{
//console.log("升级包");
that.upgradeType = 'wgt'
that.upgradeUrl = update_url
}
if(platform == 'ios' && this.upgradeType == 'pkg'){
plus.runtime.openURL(that.upgradeUrl);
}else{
var downloadTask = uni.downloadFile({
url: this.upload+update_url,
success: (downloadResult) => {
console.log(JSON.stringify(downloadResult)+"====");
if (downloadResult.statusCode === 200) {
console.log('下载成功');
plus.runtime.install(downloadResult.tempFilePath, {
force: false
}, function() {
plus.runtime.restart();
}, (e) => {
console.log(e);
uni.showToast({
title: '安装升级包失败',
icon: 'none'
})
});
}else{
uni.showToast({
title:'request fail',
icon:'none'
})
}
}
});
uni.showLoading({
mask: true,
title: "请稍等正在下载中..."
});
downloadTask.onProgressUpdate((e)=>{
that.progress = e.progress;
// 测试条件,取消下载任务。
/* if (e.progress> 50) {
downloadTask.abort();
} */
if(e.progress>=100){
console.log("下载完毕")
uni.hideLoading();
}
})
}
}