WeChat Open Platform

Mini Programs Documentation

Compatibility

Mini Program functions are constantly increasing, but old versions of the WeChat client do not support new functions. They therefore need to be made compatible when using these new capabilities.

The descriptions in document component and API pages will include the version numbers supported by various functions.

Mini Program base library version numbers can be obtained via wx.getSystemInfo or wx.getSystemInfoSync.

wx.canIUse details can also be used to determine whether the corresponding API or component can be used directly under these base library versions.

Compatibility mode - interface

New APIs can use the following code to determine whether they support a user's phone.

if (wx.openBluetoothAdapter) {
  wx.openBluetoothAdapter()
} else {
  // If you want users to experience your Mini Program on the latest version of the client, you can prompt them like this
  wx.showModal({
    title: 'Prompt',
    content: 'The current WeChat version is too old and is unable to use this function. Please try again after updating to the latest WeChat version.'
  })
}

Compatibility mode - parameters

API parameters or return values with new parameters can be determined using the following code.

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

Compatibility mode - components

New component attributes will not be processed on old versions, but errors will also not be reported. If a particular scene requires some downgrade processing on an old version, it can be done like this.

Page({
  data: {
    canIUse: wx.canIUse('button.open-type.contact')
  }
})
<button wx:if="{{canIUse}}" open-type="contact"> Service Center message </button>
<contact-button wx:else></contact-button>