编程语言
首页 > 编程语言> > 小程序更新问题:新版本发布后为什么不更新?

小程序更新问题:新版本发布后为什么不更新?

作者:互联网

uniapp微信小程序更新检测
官方文档是这样写哒~
在这里插入图片描述
解决方法:

// 版本检测更新
        async checkForUpdate() {
            const updateManager = uni.getUpdateManager();
            try {
                await new Promise((resolve, reject) => {
                    updateManager.onCheckForUpdate((res) => {
                        !res.hasUpdate && reject('无需更新');
                    });
                    updateManager.onUpdateFailed(function (res) {
                        reject('新的版本下载失败');
                    });
                })
                updateManager.onUpdateReady(async (res) => {
                    let modalRes = await this.$uni.showModal({
                        title: '更新提示',
                        content: '新版本已经准备好,是否重启应用?',
                    });
                    if (modalRes.confirm) {
                        // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                        updateManager.applyUpdate();
                    }
                });
            } catch (e) {
                setTimeout(this.checkForUpdate, 30 * 1000);
            }
        }
async onLaunch() {
        await this.checkForUpdate();
    },

标签:checkForUpdate,res,程序,updateManager,更新,版本,reject
来源: https://blog.csdn.net/limpid_changli/article/details/115865153