Small micro-channel program - forced mobile terminal update

Update mechanism applet

After the developer released a new version of the applet management background, if a user has a local applet version of history, it may still be open at this time the old version. Micro-channel client will have the opportunity to examine a number of locally cached applet has not updated version, if there will be a silent update to the new version. In general, developers in the background after a new release, it can not immediately affect all current network users, but in the worst case, also issued after the release of the new version information to the user within 24 hours. Next time the user will first update to the latest version on again when opened.

Updates at Startup

Applet every time a cold start , the checks for an updated version, if you find a new version, it will download the new version of the asynchronous code package, while the local packet starts with the client that the new version of the applet to wait the next cold start will be on the application.

Concept of cold / hot start and foreground / background, refer to the program documentation small operating mechanism

It can be wx.getUpdsateManagerused to force the user to update the new version of the API at startup.

        wx.showLoading({
            title: '加载中..',
            mask: true
        })

        const updateManager = wx.getUpdateManager()

        updateManager.onCheckForUpdate(function (res) {
            // 请求完新版本信息的回调
            console.log('是否有新版本: ', + res.hasUpdate)
            if (!res.hasUpdate) {
                wx.hideLoading()
            } 
        })

        updateManager.onUpdateReady(function () {
            wx.hideLoading()
            wx.showModal({
                title: '更新提示',
                content: '新版本已经准备好,是否重启应用?',
                showCancel: false,
                success: function (res) {
                    if (res.confirm) {
                        // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
                        updateManager.applyUpdate()
                    }
                }
            })
        })

        updateManager.onUpdateFailed(function () {
            wx.hideLoading();
            wx.showModal({
                title: '提示',
                content: '检查到有新版本,但下载失败,请检查网络后重试',
                showCancel: false
            })
        })

        setTimeout(wx.hideLoading, 5000)

Because onCheckForUpdatethere will be some delay in the time to check for new versions (on development tools is probably about four seconds), in order to prevent the process of checking the new version the user triggers the operation out of the home, added a wx.showLoadingbe covered.

Note that the above code update to the new version also will not take effect immediately, so users still need to conduct a cold start.

Reference: https://developers.weixin.qq.com/miniprogram/dev/framework/runtime/update-mechanism.html

Guess you like

Origin www.cnblogs.com/thunderLL/p/10963823.html