在应用生命周期 onLaunch
中调用下列代码
// #ifdef MP
// 小程序更新
mpUpdate(){
const updateManager=uni.getUpdateManager();
// 请求完新版本信息的回调
updateManager.onCheckForUpdate(function(res){
if(res.hasUpdate){
updateManager.onUpdateReady(function(data){
// 新版本下载好,重启小程序
updateManager.applyUpdate();
})
}
})
// 新版本下载失败
updateManager.onUpdateFailed(function(res){
uni.showModal({
title:'提示',
content:'检查到有新版本,但下载失败,请检查网络设置',
showCancel:false,
success(){
updateManager.applyUpdate();
}
})
})
}
// #endif