May 19, 2021 WeChat Mini Program Development Document
Base library 1.9.90 starts to support, and low versions need to be compatible
Gets a globally unique version update manager for managing small program updates.
For updates to small programs, you can view the Run Mechanism documentation.
A list of methods for the updateManager object:
Method | Parameters | Description |
---|---|---|
onCheckForUpdate | callback | When a new version of the information is requested from WeChat background, a callback is made |
onUpdateReady | callback | When the new version is downloaded, a callback is made |
onUpdateFailed | callback | When the new version download fails, a callback is made |
applyUpdate | When the new version download is complete, calling the method forces the new version on the current gadget to be applied and restarted |
OnCheckForUpdate (callback) callback results note:
Property | Type | Description |
---|---|---|
hasUpdate | Boolean | Is there a new version? |
Note: Checking for updates is automatically triggered by WeChat when a small program starts cold, without being actively triggered by the developer, the developer simply listens to the results of the check.
OnUpdateReady (callback) callback result description:
When WeChat checks for a new version of a small program, it actively triggers a download operation (without a developer trigger), and when the download is complete, the developer is informed via onUpdateReady.
OnUpdateFailed (callback) callback results note:
When WeChat checks for a new version of a small program, it actively triggers a download operation (without a developer trigger), and informs the developer via onUpdateFailed if the download fails (possibly for network reasons, etc.).
ApplyUpdate () Description:
When the new version of the applet has been downloaded (i.e., the onupdateready callback) can enforce the applet and apply the latest version through this method.
Sample code:
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
})
updateManager.onUpdateFailed(function () {
// 新的版本下载失败
})