UpdateManager Overview

The UpdateManager object is used to manage the mini program updates. Call my.getUpdateManager to obtain an UpdateManager instance.

Methods

Name

Description

UpdateManager.applyUpdate

Force to restart the mini program and update to the latest version. This API is called after the onUpdateReady callback is received, which means that the new version of the mini program is downloaded.

UpdateManager.onCheckForUpdate

Listen for the event that a request is sent to the server to check  for updates.

UpdateManager.onUpdateReady

Listen for the event that a newer mini program version is available. 

UpdateManager.onUpdateFailed

Listen for the event that the mini program update is failed. 

Sample code

copy
const updateManager = my.getUpdateManager()

updateManager.onCheckForUpdate(function (res) {
  // Callback of onCheckForUpdate
  console.log(res.hasUpdate)
})

updateManager.onUpdateReady(function () {
  my.confirm({
    title: 'Update reminder',
    content: 'The new version is ready. Do you want to restart the mini program?',
    success: function (res) {
      if (res.confirm) {
        // The new version is downloaded. Call UpdateManager.applyUpdate to restart and apply the new version.
        updateManager.applyUpdate()
      }
    }
  })
})

updateManager.onUpdateFailed(function () {
  // The new version of the mini program is failed to be downloaded.
})