title: UpdateManager.onUpdateFailed header: develop nav: api

sidebar: UpdateManager-onUpdateFailed

解释:当新版本下载失败,会进行回调

方法参数

Function callback

示例

在开发者工具中预览效果

扫码体验

sidebar: UpdateManager-onUpdateFailed - 图1 请使用百度APP扫码

代码示例

  • 在 swan 文件中

    1. <view class="container">
    2. <view class="card-area">
    3. <view class="top-description border-bottom">此api会在旧版小程序在拉到最新包失败时触发</view>
    4. </view>
    5. </view>
  • 在 js 文件中

    1. Page({
    2. data: { },
    3. onLoad() {
    4. const updateManager = swan.getUpdateManager();
    5. updateManager.onUpdateFailed(function (res) {
    6. // 请求完新版本信息的回调
    7. console.log("res", res);
    8. if(!res.hasUpdate){
    9. swan.showModal({
    10. title: '更新提示',
    11. content: '版本更新失败,请重试',
    12. });
    13. }
    14. });
    15. }
    16. });