小程序开放平台

文档中心
基础
canIUse
base64ToArrayBuffer
arrayBufferToBase64
系统
小程序
更新
getUpdateManager
UpdateManager
applyUpdate
onCheckForUpdate
onUpdateFailed
onUpdateReady
路由
跳转
转发
界面
网络
支付
数据缓存
媒体
位置
开放接口
设备
XHSML
性能
第三方平台
文件
数据分析
画布

xhs.onCheckForUpdate

开发
>
JS API
>
基础
>
更新
>
UpdateManager
>
onCheckForUpdate
>
更新时间:2025-04-10 15:29:10

以Promise风格调用: 不支持

监听向小红书后台请求检查更新结果事件。小红书在小程序每次启动(不包括热启动)时自动检查更新,不需由开发者主动触发。

参数

function callback

参数

属性
类型
说明
hasUpdateboolean是否有新版本

实例代码

App({
  onLaunch() {
    // 此处仅为效果展示,建议在app.js中的OnLaunch()中调用
    const updateManager = xhs.getUpdateManager();
    updateManager.onCheckForUpdate((res) => {
      xhs.showToast({
        title: (res.hasUpdate ? "有" : "无") + "可用更新版本",
        icon: "none",
      });
    });
  },
});
该文档是否对您有帮助?