当前位置:网站首页>Applet system update prompt, and force the applet to restart and use the new version

Applet system update prompt, and force the applet to restart and use the new version

2022-07-06 22:17:00 kaka-333

Wechat development documents api Address :UpdateManager | Wechat open documents

app.js In file

 onLaunch: function () { // Start the applet to execute once 

      this.getNewSystem()

}

getNewSystem() {

      if (wx.canIUse('getUpdateManager')){

        const updateManager = wx.getUpdateManager()// Manage applet updates 

        updateManager.onCheckForUpdate(function (res) {

          console.log(res)

          if (res.hasUpdate) {//res.hasUpdate return boolean type 

            updateManager.onUpdateReady(function () {

              wx.showModal({

                title: ' Update hints ',

                content: ' The new version is ready , Restart the current application ?',

                success(res) {

                  if (res.confirm) {

                    //  The new version has been downloaded , call applyUpdate Apply new version and restart 

                    updateManager.applyUpdate()

                  }

                }

              })

            })

            //  Execute when the download of the new version fails 

            updateManager.onUpdateFailed(function () {

              wx.showModal({

                title: ' Find a new version ',

                content: ' Please delete the current applet , Search again and open ...',

              })

            })

          }

        })

      }else{

        // If the applet needs to experience in the latest wechat version , Here are some tips 

        wx.showModal({

          title: ' Update hints ',

          content: ' Current wechat version is too low , This feature is not available , Please upgrade to the latest wechat version and try again .'

        })

      }

    },

原网站

版权声明
本文为[kaka-333]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061422258655.html