# mt.getUpdateManager()
获取版本更新管理器对象,用于管理小程序更新。
# 支持情况
| 项 | 说明 |
|---|---|
| 兼容性 | 兼容微信 |
# 参数
无参数。
# 返回值
返回 UpdateManager 对象。
# 示例代码
const updateManager = mt.getUpdateManager()
updateManager.onCheckForUpdate((res) => {
console.log('是否有新版本:', res.hasUpdate)
})
updateManager.onUpdateReady(() => {
mt.showModal({
title: '更新提示',
content: '新版本已准备好,是否重启更新?',
success(res) {
if (res.confirm) {
updateManager.applyUpdate()
}
}
})
})
updateManager.onUpdateFailed(() => {
console.error('更新失败')
})
# 与微信差异
微信小游戏的 wx.getUpdateManager 返回全局唯一实例,多次调用返回同一对象;美团小游戏每次调用均返回新实例。如需复用同一管理器,请在业务代码中自行缓存返回值。