微信小程序更新版本,监测并用户提示

2021/4/7 12:08:29

本文主要是介绍微信小程序更新版本,监测并用户提示,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

写在app.js文件中onLaunch中

 

//console.log('onLaunch:', options);
    // 检测并获取小程序更新 api 说明:https://developers.weixin.qq.com/miniprogram/dev/api/getUpdateManager.html
    if (wx.canIUse('getUpdateManager')) { // 基础库 1.9.90 开始支持,低版本需做兼容处理
        const updateManager = wx.getUpdateManager();
        updateManager.onCheckForUpdate(function(result) {
            if (result.hasUpdate) { // 有新版本
                updateManager.onUpdateReady(function() { // 新的版本已经下载好
                    wx.showModal({
                        title: '更新提示',
                        content: '新版本已经下载好,请重启应用。',
                        success: function(result) {
                            if (result.confirm) { // 点击确定,调用 applyUpdate 应用新版本并重启
                                updateManager.applyUpdate();
                            }
                        }
                    });
                });
                updateManager.onUpdateFailed(function() { // 新的版本下载失败
                    wx.showModal({
                        title: '已经有新版本了哟~',
                        content: '新版本已经上线啦~,请您删除当前小程序,重新搜索打开哟~'
                    });
                });
            }
        });
    }
    else { // 有更新肯定要用户使用新版本,对不支持的低版本客户端提示
        wx.showModal({
            title: '温馨提示',
            content: '当前微信版本过低,无法使用该应用,请升级到最新微信版本后重试。'
        });
    }



这篇关于微信小程序更新版本,监测并用户提示的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程