小程序版
官方链接地址
uni.getUpdateManager()
本API返回全局唯一的版本更新管理器对象: updateManager,用于管理小程序更新。
onCheckForUpdate callback 当向小程序后台请求完新版本信息,会进行回调
onUpdateReady callback 当新版本下载完成,会进行回调
onUpdateFailed callback 当新版本下载失败,会进行回调
applyUpdate 当新版本下载完成,调用该方法会强制当前小程序应用上新版本并重启
onCheckForUpdate 回调结果说明
hasUpdate Boolean 是否有新的版本
// 在APP.vue中添加
onLaunch: function() {
const updateManager = uni.getUpdateManager(); // 获取更新管理器对象
updateManager.onCheckForUpdate(function(res) {
if (res.hasUpdate) {
updateManager.onUpdateReady(function() {
uni.showModal({
title: '更新提示',
content: '新版本已经准备好,点击确定重新启动',
showCancel: false,
success: res => {
if (res.confirm) {
updateManager.applyUpdate();
}
}
})
})
updateManager.onUpdateFailed(function() {
uni.showModal({
title: '提示',
content: '检查到有新版本,但是下载失败,请检查网络设置',
showCancel: false
})
})
}
})
},
APP版(热更新)
APP热更新版本