compareVersion(version1, version2) {
let v1 = version1.split('.').map(m => parseInt(m));
let v2 = version2.split('.').map(m => parseInt(m));
for (let i = 0; i < v1.length && i < v2.length; i++) {
if (v1[i] < v2[i]) return -1;
if (v1[i] > v2[i]) return 1;
}
if (v1.length < v2.length) return -1;
if (v1.length > v2.length) return 1;
return 0;
}
使用
checkUpdate() {
plus.runtime.getProperty(plus.runtime.appid, info => {
var localVersion = info.version;
let ua = uni.getSystemInfoSync().platform;
if (/android/i.test(ua)) {
this.$http.SSO.Apk.GetInfo().then(res => {
if (res.ok && res.data) {
var remoteInfo = res.data;
if (this.$utility.compareVersion(localVersion, remoteInfo.version) < 0) {
uni.showModal({
title: '更新提示',
content: '发现新版本' + remoteInfo.version + ',是否更新?',
success: res => {
if (res.confirm)
this.updateApk(remoteInfo.url);
else if (res.cancel)
uni.showToast({
icon: 'none',
title: '取消了更新',
});
}
});
}
}
});
}
});
},