Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Compatible


May 18, 2021 WeChat Mini Program Development Document



The functionality of small programs is constantly increasing, but older versions of WeChat clients do not support new features, so compatibility is required when using these new capabilities.

The documentation includes the version numbers supported by each feature in the description of the components, APIs, and other pages.

You can get the base library version number of the wx.getSystemInfoSync wx.getSystemInfo

You can also wx.canIUse details to determine whether the corresponding API or component can be used directly under the underlying library version

Compatible way - interface

For new APIs, you can use the following code to determine whether the user's phone is supported.

if (wx.openBluetoothAdapter) {
  wx.openBluetoothAdapter()
} else {
  // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
  wx.showModal({
    title: '提示',
    content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
  })
}

Compatible way - parameters

For parameters of the API or new parameters for return values, you can judge by the following code.

wx.showModal({
  success: function(res) {
    if (wx.canIUse('showModal.cancel')) {
      console.log(res.cancel)
    }
  }
})

Compatibility - Components

For components, new properties are not processed on older versions, but no errors are reported. If a particular scenario requires some downgrading of the old version, you can do so.

Page({
  data: {
    canIUse: wx.canIUse('button.open-type.contact')
  }
})
<button wx:if="{{canIUse}}" open-type="contact"> 客服消息 </button>
<contact-button wx:else></contact-button>