HomeDocs
Skip to main content

UpdateManager

Introduction

The UpdateManager object is used for managing updates and can be obtained through the dlt.getUpdateManager interface.

Methods

  1. UpdateManager.applyUpdate()
    Forcefully restarts the mini-program and uses the new version. Call this method when the new version of the mini-program has been downloaded (i.e., when the onUpdateReady callback is received).

  2. UpdateManager.onCheckForUpdate(function listener)
    Listens for events related to checking for update results from the backend. The mini-program automatically checks for updates on every launch, including hot restarts, without the need for developer-triggered actions.

  3. UpdateManager.onUpdateReady(function listener)
    Listens for events when the mini-program has an update available. The client initiates the download automatically (without developer intervention), and the callback is triggered upon a successful download.

  4. UpdateManager.onUpdateFailed(function listener)
    Listens for events when the mini-program update process fails. When a new version is available for the mini-program, the client initiates the download automatically (without developer intervention). If the download fails (possibly due to network issues), this callback is triggered.

  5. UpdateManager.forceUpdateAppInfo()
    Actively initiates an AppInfo request to obtain update result information.

  6. UpdateManager.downloadNew()
    Actively initiates the download of the latest mini-program package. This is effective after actively initiating an AppInfo request using UpdateManager.forceUpdateAppInfo().

Sample Code

const updateManager = dlt.getUpdateManager();

// 1. Automated update process
updateManager.onCheckForUpdate(function (res) {
// Callback after requesting new version information
console.log(res.hasUpdate);
});

updateManager.onUpdateReady(function () {
dlt.showModal({
title: 'Update Prompt',
content:
'A new version is ready. Would you like to restart the application?',
success: function (res) {
if (res.confirm) {
// The new version has been downloaded; call applyUpdate to apply the new version and restart.
updateManager.applyUpdate();
}
},
});
});

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

// 2. Actively initiate the update process
updateManager.forceUpdateAppInfo({
success: (res) => {
// Check for a new version update
if (res.hasUpdate) {
// Actively initiate the download of the latest mini-program package
updateManager.downloadNew({
success: (res) => {
if (res.hasReady) {
dlt.showModal({
title: 'Update Prompt',
content:
'A new version is ready. Would you like to restart the application?',
success: function (res) {
if (res.confirm) {
// The new version has been downloaded; call applyUpdate to apply the new version and restart.
updateManager.applyUpdate();
}
},
});
}
},
fail: (res) => {},
complete: (res) => {},
});
}
},
fail: (res) => {},
complete: (res) => {},
});
Privacy agreementDeveloper agreementcontact us: developer_service.mi@transsion.com © 2024 MiniApp. All Rights Reserved.