title: Taro.getUpdateManager()

sidebar_label: getUpdateManager

获取全局唯一的版本更新管理器,用于管理小程序更新。 关于小程序的更新机制,可以查看运行机制文档。

支持情况:getUpdateManager - 图1 getUpdateManager - 图2 getUpdateManager - 图3

参考文档

类型

  1. () => UpdateManager

示例代码

  1. const updateManager = Taro.getUpdateManager()
  2. updateManager.onCheckForUpdate(function (res) {
  3. // 请求完新版本信息的回调
  4. console.log(res.hasUpdate)
  5. })
  6. updateManager.onUpdateReady(function () {
  7. Taro.showModal({
  8. title: '更新提示',
  9. content: '新版本已经准备好,是否重启应用?',
  10. success: function (res) {
  11. if (res.confirm) {
  12. // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
  13. updateManager.applyUpdate()
  14. }
  15. }
  16. })
  17. })
  18. updateManager.onUpdateFailed(function () {
  19. // 新的版本下载失败
  20. })