百度智能小程序 获取版本更新管理器

2020-09-05 11:02 更新

swan.getUpdateManager

基础库 1.13.4 开始支持,低版本需做兼容处理。

解释:获取全局唯一的版本更新管理器,用于管理小程序更新。

Web 态说明:Web 态小程序暂不支持手动管理小程序更新。

方法参数

无返回值 :UpdateManager

示例 

在开发者工具中打开


图片示例


代码示例

<view class="wrap">

    <view class="card-area">

        <view class="top-description border-bottom">applyUpdate</view>

        <button type="primary" bindtap="applyUpdate">button</button>   

    </view>

</view

Page({

    onLoad() {

        this.updateManager = swan.getUpdateManager();

        this.updateManager.onUpdateReady(res => {

            swan.showModal({

                title: '更新提示',

                content: '新版本已经准备好,是否重启应用?',

                success:res => {

                    if (res.confirm) {

                        // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启

                        this.updateManager.applyUpdate();

                    }

                }

            });

        });

        this.updateManager.onUpdateFailed(err => {

            // 新的版本下载失败

            console.log('版本下载失败原因', err);

            swan.showToast({

                title: '新版本下载失败,请稍后再试',

                icon: 'none'

            });

        });

    },

    applyUpdate() {

        this.updateManager.onCheckForUpdate(res => {

            // 请求完新版本信息的回调

            if (!res.hasUpdate) {

                swan.showToast({

                    title: '无可用更新版本',

                    icon: 'none'

                });

            }

        });

    }

}


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号