admin管理员组

文章数量:1576358

当我们发布了新版本,因为缓存的缘故用户使用的小程序可能还是旧版的,于是我们就有了提醒用户更新版本的需要。小程序提供了UpdateManager对象,用来管理更新,基础库 1.9.90 开始支持,低版本需做兼容处理。

//app.js
App({
    onLaunch: function () {
        this.checkNewVersion();
    },
    checkNewVersion: function () { // 检查版本更新
        // 获取小程序更新机制兼容
        if (wx.canIUse("getUpdateManager")) {
            const updateManager = wx.getUpdateManager();
            updateManager.onCheckForUpdate(function (res) {
                // 请求完新版本信息的回调
                if (res.hasUpdate) {
                    updateManager.onUpdateReady(function () {
                        wx.showModal({
                            title: "更新提示",
                            content: "新版本已经准备好,是否重启应用?",
                            success: function (res) {
                                if (res.confirm) {
                                    // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                                    updateManager.applyUpdate();
                                }
                            }
                        });
                    });
                    updateManager.onUpdateFailed(function () {
                        // 新的版本下载失败
                        wx.showModal({
                            title: "已经有新版本了哟~",
                            content: "新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~"
                        });
                    });
                }
            });
        } else {
            // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
            wx.showModal({
                title: "提示",
                content: "当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。"
            });
        }
    }
});

参考链接

https://developers.weixin.qq/miniprogram/dev/api/getUpdateManager.html
https://developers.weixin.qq/miniprogram/dev/api/update/wx.getUpdateManager.html
https://developers.weixin.qq/miniprogram/dev/api/update/UpdateManager.html

本文标签: 版本程序微信小