Operating mechanism and update mechanism applets

Operating mechanism applet

Cold start and hot start

Cold start: After the first time you open and destroy open again

Hot start (do not restart): it has opened, opened again within 5 minutes, switching directly to the front

 

Foreground  and background

When the applet is running: Reception

Click to leave :( background, or home key to leave the micro-letter) to leave but did not destroy

 

Destruction of small programs

After the applet into the background, (5 minutes) is not destroyed immediately, may be destroyed after 5 minutes,

If the program takes up little system resources is too high, sustainable resource-intensive, it will be destroyed or micro-channel system of the client's recovery initiative

 

Update mechanism

Detects the version update

https://developers.weixin.qq.com/miniprogram/dev/api/base/update/UpdateManager.html

use:

//Check for updates
checkUpdate(){
  const updateManager = wx.getUpdateManager()
  // detects the version update
  updateManager.onCheckForUpdate((res1)=>{
    console.log("onCheckForUpdate.res:", res1) //{hasUpdate: false}
    if (res1.hasUpdate){
      console.log("hasUpate")
      updateManager.onUpdateReady(()=>{
        console.log("onUpdateReady")
        wx.showModal({
          title: 'update prompt'
          content: 'The new version is ready, whether to restart the application? '
          success: function(res){
            console.log("success res:", res)//{errMsg:"showModal:ok",cancel:false,confirm:true}
            if (res.confirm) {
              // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
              updateManager.applyUpdate()
            }
          }
        })
      })
      updateManager.onUpdateFailed(function () {
        // 新版本下载失败
        console.log("onUpdateFailed")
      })
 
    }
  })
}

  

 

 

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/baixinL/p/12002257.html