onLaunch: function () {
let that = this;
uni.getSystemInfo({
success(res) {
that.platform = res.platform; // 获取系统平台 ios 安卓
},
});
// 获取应用属性
plus.runtime.getProperty(plus.runtime.appid, function (inf) {
that.version = plus.runtime.versionCode;
console.log(that.version);
});
uni.request({
method: "GET",
url: "服务端响应的最新apk版本信息",
header: {
"Content-Type": "application/x-www-form-urlencoded",
},
})
.then((res) => {
let data = res.data;
if (!data.code) {
if (that.version != data.data.versionCode && that.version < data.data.versionCode) {
let contentText = `APP已发布新版本${data.data.versionName},为了您的正常使用体验,请更新版本后使用`;
let downloadText = "下载成功,现在安装吗";
let downloadtip = "正在下载";
uni.showModal({
title: "更新提示",
content: contentText,
cancelText: "取消",
confirmText: "去更新",
success: function (res) {
if (res.confirm) {
if (that.platform == "android") {
var prg = 0;
var showLoading = plus.nativeUI.showWaiting(downloadtip); //创建一个showWaiting对象
// 执行下载
var downloadTask = uni.downloadFile({
url: data.data.download, // 下载地址
success: (downloadResult) => {
plus.nativeUI.closeWaiting();
if (downloadResult.statusCode == 200) {
uni.showModal({
title: "",
content: downloadText,
confirmText: "安装",
cancelText: "取消",
confirmColor: "#EE8F57",
success: (res) => {
if (res.confirm) {
plus.runtime.install(downloadResult.tempFilePath, {
force: true,
});
}
},
});
}
},
});
downloadTask.onProgressUpdate((res) => {
that.progressNum = res.progress;
prg = parseInt(res.progress);
showLoading.setTitle(downloadtip + prg + "% ");
});
} else if (that.platform == "ios") {
var appurl = "ios应用商店的应用地址";
plus.runtime.openURL(appurl, function (res) {
console.log(res);
});
}
} else if (res.cancel) {
}
},
});
}
}
})
.catch((err) => {
console.log(err);
});
},