將這段函數放在小程序裏就可以
const version = wx.getSystemInfoSync().SDKVersion;
if (this.compareVersion(version, '1.9.9') >= 0) {
const updateManager = wx.getUpdateManager();
updateManager.onCheckForUpdate(function (res) {
// 請求完新版本信息的回調
console.log(res.hasUpdate)
});
updateManager.onUpdateReady(function () {
wx.showModal({
title:'更新提示',
content:'新版本已經準備好,是否馬上重啓小程序?',
success:function (res) {
if (res.confirm) {
// 新的版本已經下載好,調用 applyUpdate 應用新版本並重啓
updateManager.applyUpdate()
}
}
})
});
updateManager.onUpdateFailed(function () {
// 新的版本下載失敗
uni.showModal({
title: '下載失敗,請手動刪除小程序,重新下載',
icon: 'none',
mask: true
});
});
}