title: UpdateManager.onCheckForUpdate header: develop nav: api

sidebar: UpdateManager-onCheckForUpdate

解释:当向百度后台请求完新版本信息,会进行回调。

方法参数

Function callback

参数说明

属性 类型 说明
hasUpdate Boolean 是否有新的版本

示例

在开发者工具中预览效果

扫码体验

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

代码示例

  • 在 swan 文件中
  1. <view class="container">
  2. <view class="card-area">
  3. <view class="top-description border-bottom">onCheckForUpdate</view>
  4. <button type="primary" bindtap="bindOnCheckForUpdate">button</button>
  5. </view>
  6. </view>
  • 在 js 文件中
    1. Page({
    2. data: {},
    3. bindOnCheckForUpdate() {
    4. const updateManager = swan.getUpdateManager();
    5. updateManager.onCheckForUpdate(function (res) {
    6. // 请求完新版本信息的回调
    7. console.log("res", res.hasUpdate);
    8. if(!res.hasUpdate){
    9. swan.showModal({
    10. title: '更新提示',
    11. content: '无可用更新版本',
    12. });
    13. }
    14. });
    15. }
    16. });