# UpdateManager

UpdateManager Object to manage updates, available through the wx.getUpdateManager Interface gets an instance.

# method

# UpdateManager.applyUpdate()

Force the Mini Program to restart and use the new version. After the new version of the Mini Program has been downloaded (i.e. received onUpdateReady Callback) call.

# UpdateManager.onCheckForUpdate(function callback)

Monitor the WeChat background request to check the update results event. WeChat automatically checks updates when the Mini Program is cold started, without the developer taking the initiative to trigger.

# UpdateManager.onUpdateReady(function callback)

Listening Mini Program has a version update event. Active client trigger download (no developer trigger), download success callback

# UpdateManager.onUpdateFailed(function callback)

Listen for Mini Programs to update failed events. Mini Program has a new version, the client active trigger download (without developer trigger), download failure (may be network reasons, etc.) after the callback

# sample code

const updateManager = wx.getUpdateManager()

updateManager.onCheckForUpdate(function (res) {
  // Callback after requesting new version information
  console.log(res.hasUpdate)
})

updateManager.onUpdateReady(function () {
  wx.showModal({
    title: 'Update tip ',
    content: 'The new version is ready, reboot the app? ' ',
    success: function (res) {
      if (res.confirm) {
        // The new version has been downloaded and calls applyUpdate Apply a new version and restart
        updateManager.applyUpdate()
      }
    }
  })
})

updateManager.onUpdateFailed(function () {
  // New version download failed
})

# Tips

  1. WeChat developer tool can be accessed throughCompile modeDownNext compile simulation updateSwitch to debug
  2. Mini Program development version/No experience version.versionConcepts, so cannot be used in the development version/Test Update Update for Trial Edition