微信小程序版本自动更新用户感知提示方案总结
需求背景
- 最近基于uniapp开发微信小程序上线后,在迭代版本后期望自动更新提示。
- 使感知。
解决方案
-
使用全局唯一的对象: updateManager。
-
// 方案如下: const updateManager = uni.getUpdateManager() updateManager.onCheckForUpdate((res) => { if (res.hasUpdate) { updateManager.onUpdateReady(() => { uni.showModal({ title: '更新提示', content: '新版本已经准备好,是否重启应用?', success(res) { if (res.confirm) { updateManager.applyUpdate() } } }) }) updateManager.onUpdateFailed(() => { uni.showModal({ content: '新版本更新失败,请关闭应用后重启', showCancel: false, confirmText: '知道了' }) }) } })
-
解决。