I believe that many small developers who have encountered this situation: applet has released a new official version, but many users still using an older version of the applet. For example: If the version management is chaotic, then multiple versions of applets point to the same back-end server, then there may be compatibility problems between the new and old versions, giving users a bad experience.
The cause of the situation: after a small program released the latest version, the old version of the user's local presence also of small programs, small micro-channel may not check the updated version of the program at this time, this will lead users still using the old version. The result: a new version of the applet publication can not be guaranteed immediately affect all applets users .
Solution: Developers can use the API to wx.getUpdateManager update applet. Sample code is as follows:
Screenshots and code are the same.
/**
* Check the version of the update applet
* @Param isForce whether to force update
*/
function versionUpdate(isForce = false) {
// determine the current version of the API is available getUpdateManager
if (wx.canIUse("getUpdateManager")) {
// Get globally unique version of the Update Manager for managing small updates
const updateManager = wx.getUpdateManager();
// listens for requests to check for updates to the micro letter backstage event results
updateManager.onCheckForUpdate(function(res) {
// End callback request new version information
if (res.hasUpdate) {
// there is a new version. There monitor applet version update event
updateManager.onUpdateReady(function() {
if (isForce) {
// force the applet rebooted with a new version
updateManager.applyUpdate();
} else {
// prompt the user to update the version information
wx.showModal({
title: "version update prompt"
content: "The new version is ready, whether to restart the application?"
success(res) {
if (res.confirm) {
// The new version has been downloaded well, call the new version of the application and restart applyUpdate
updateManager.applyUpdate();
}
}
});
}
});
// Listen applet update failed events. A subsequent operation, the developer may themselves.
updateManager.onUpdateFailed(function() {
wx.showModal({
title: "There has been a new version of the yo ~",
content: "The new version has been on-line friends ~, please delete the current applet, re-open the search yo ..."
});
});
}
});
} else {
// prompts the user to upgrade version
wx.showModal({
title: "prompt"
content: "The current micro-channel version is too low, you can not use this feature, please upgrade to the latest micro-channel version and try again."
});
}
}