onReady() {
// #ifdef APP-PLUS
// app获取版本
var _this = this;
_this.getVersion();
// #endif
},
methods: {
/**
* app端版本更新 start
*/
getVersion() {
let _this = this;
let platform = uni.getSystemInfoSync().platform;
console.log(platform);
// 获取应用版本信息
plus.runtime.getProperty(plus.runtime.appid, (wgtinfo) => {
console.log("==获取应用版本信息==");
console.log(JSON.stringify(wgtinfo));
console.log(wgtinfo.versionCode);
var versionCode = wgtinfo.versionCode;
uni.$u.http.get('/api/other.Webconfig/get_webconfigdata', {
params: {}
}).then(res => {
console.log("==检查版本更新==");
console.log(res);
// 下载地址
var androidUrl = res.data.web_config_str.app_android_url;
var iosUrl = res.data.web_config_str.app_ios_url;
// 新版本
var androidVersion_new = res.data.web_config_str.app_android_version_code;
var iosVersion_new = res.data.web_config_str.app_ios_version_code;
// 安卓版本对比,是否更新
if (parseInt(androidVersion_new) > parseInt(versionCode) && platform ==
'android') {
uni.showModal({
title: "发现新版本",
content: "确认下载更新?",
success: (res) => {
if (res.confirm) {
// console.log('用户点击确定');
_this.downloadAndroid(androidUrl);
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
}
// ios版本对比,是否更新
if (parseInt(iosVersion_new) > parseInt(versionCode) && platform == 'ios') {
uni.showModal({
title: "发现新版本",
content: "确认下载更新?",
success: (res) => {
if (res.confirm) {
// console.log('用户点击确定');
plus.runtime.launchApplication({
action: iosUrl
}, function(e) {
console.log(
'Open system default browser failed: ' +
e.message);
});
} else if (res.cancel) {
console.log('用户点击取消');
}
}
})
}
}).catch(res => {
console.log(res);
})
})
},
// 下载安卓端app
downloadAndroid(androidUrl) {
uni.showLoading({
title: '更新中...'
})
// 执行下载
uni.downloadFile({
url: androidUrl,
success: (downloadRes) => {
uni.hideLoading();
if (downloadRes.statusCode == 200) {
uni.showModal({
title: '更新成功',
content: '是否现在重启吗?',
confirmText: '重启',
confirmColor: '#EE8F57',
success: function(res) {
if (res.confirm == true) {
//安装
plus.runtime.install(
downloadRes.tempFilePath, {
force: true
},
function(res) {
utils.showToast('更新成功,重启中');
plus.runtime.restart();
}
);
}
}
});
}
}
});
},
/**
* app端版本更新 end
*/
}
uniapp打包app后,安卓端、IOS端版本升级
于 2023-06-20 12:10:06 首次发布