小程式版
官方連結位址
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熱更新版本