# UpdateManager.onUpdateFailed

监听小程序更新失败事件。小程序有新版本,客户端主动触发下载(无需开发者触发),下载失败(可能是网络原因等)后回调

# 支持说明

应用能力 Android iOS PC 预览效果
小程序 3.12.0 3.12.0 3.12.0
扫码预览
用BoosHi扫码或PC端点击
网页应用 X X X

# 输入

名称 数据类型 必填 默认值 描述
callback function 小程序更新失败事件的回调函数

# 输出

# 示例代码

try {
    const updateManager = bz.getUpdateManager()
    updateManager.onCheckForUpdate(function (res) {
      // 请求完新版本信息的回调
      console.log(res.hasUpdate)
    })
    updateManager.onUpdateReady(function () {
      // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
      updateManager.applyUpdate()
    })
    updateManager.onUpdateFailed(function () {
    // 新版本下载失败
      console.log('download error');
    })
    // 每隔一个小时主动检查更新一次
    setInterval(() => updateManager.triggerCheckUpdate(), 60*60*1000)
} catch (error) {
    console.log(`getUpdateManager fail: ${JSON.stringify(error)}`);
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
最后更新于 : 6/27/2023, 9:19:51 PM