The general idea is as follows:
- Reason: The reason for the remote version push is probably that the app failed to be listed on the mobile application store normally, and the listing qualifications do not match, etc.
- Implementation idea: get the version number of the current app => request the new version number and new package address from the interface => compare the version number => prompt to download the update
code:
app.vue
// #ifdef APP-PLUS
let _this = this
let v = plus.runtime.versionCode
uni.getSystemInfo({
success: function (res) {
if(res.platform != 'android') return
// 获取当前已安装的app版本号 版本信息获取
_this.$store.dispatch('root/getNewVersion', {version: v})
}
});
// #endif
root.js
async getNewVersion({ commit }, data) {
// 获取新的版本号 (这里换成自己的接口)
const result = await User.getVersion(data.version)
// 不需要更新则跳过
if(!result) return
// 当前版本号保存
commit('setVersion', data.version)
// 需要新版本号等
commit('setNewVersionInfo', result)
// 更新提醒
uni.showModal({
title: '发现新版本,是否更新',
content: '待更新版本号:' + result.new_version,
success: res => {
// 点击确定
if (res.confirm) {
// 打开手机自带浏览器下载
plus.runtime.openURL(result.url)
}
// 点击取消更新
uni.$u.toast('点击取消更新')
// 安卓退出app
plus.runtime.quit();
}
});
},
Note:
- This article only uses the Android version push, so the non-Android system is screened
- Forcibly quitting the app on ios is different from that on Android, the reference for ios is as follows
-
plus.ios.import('UIApplication').sharedApplication().performSelector('exit');