my.getUpdateManager
版本要求:基础库 1.11.0 或更高版本;支付宝客户端 10.1.32 或更高版本,若版本较低,建议做 兼容处理。
创建一个 UpdateManager 对象,获取全局唯一的版本更新管理器,用于管理小程序更新。
返回值
UpdateManager
UpdateManager 概览
UpdateManager 对象,用来管理更新,可通过 my.getUpdateManager API 获取实例。
方法
示例代码
const updateManager = my.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
// 请求完新版本信息的回调
console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
my.confirm({
title: '更新提示',
content: '新版本已经准备好,是否重启应用?',
success: function (res) {
if (res.confirm) {
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(function () {
// 新版本下载失败
})