# compatible
Weixin Mini Program features are constantly being added, but older versions of WeChat do not support new features, so you need to be compatible when using these new capabilities.
Developers can achieve low version compatibility in the following ways:
# 1. Version number comparison
WeChat The version number of the Guest and Weixin Mini Program base libraries is styled Major.Minor.Patch (Major. Minor. Revision).
The document will include the minimum base library version number required for each function in the page description of components, APIs, etc.
The developer can get the version number of the base library on which the current Mini Program is running by calling wx.getAppBaseInfo in Weixin Mini Program.Run low version compatibility logic by version comparison.
Version number comparison applies in all cases. Some scenarios can also be accomplished using the methods mentioned later.
< = 2.20.1 Use wx.getSystemInfo ] ((wx.getSystemInfo))Or wx.getSystemInfoSync Get the base library version
Note: Version numbers cannot be compared directly using character string comparisons.For example, '2.29.1' > '2.3.0' is false
Version comparisons can be based on the following code:
function compareVersion(v1, v2) {
v1 = v1.split('.')
v2 = v2.split('.')
const len = Math.max(v1.length, v2.length)
while (v1.length < len) {
v1.push('0')
}
while (v2.length < len) {
v2.push('0')
}
for (let i = 0; i < len; i++) {
const num1 = parseInt(v1[i])
const num2 = parseInt(v2[i])
if (num1 > num2) {
return 1
} else if (num1 < num2) {
return -1
}
}
return 0
}
compareVersion('1.11.0', '1.9.9') // 1
const version = wx.getAppBaseInfo().SDKVersion
if (compareVersion(version, '1.1.0') >= 0) {
wx.openBluetoothAdapter()
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
# 2. Determination of API presence.
For a new API, you can determine whether the version of the base library used by the user is supported by determining whether the API exists. For example:
if (wx.openBluetoothAdapter) {
wx.openBluetoothAdapter()
} else {
// 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
wx.showModal({
title: '提示',
content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
})
}
# 3. wx.canIUse
In addition to directly judging by the version number, you can also use wx.canIUse to determine whether it can be used directly under the base library version.For example:
API parameters or return values
For API parameters or return value has a new parameter, you can judge with the following code to determine.
wx.showModal({
success: function(res) {
if (wx.canIUse('showModal.success.cancel')) {
console.log(res.cancel)
}
}
})
assembly
For components, new components or properties will not be processed on older versions, but will not be error-reported. If special scenarios require some downgrading of the older version, you can do this.
Page({
data: {
canIUse: wx.canIUse('cover-view')
}
})
<video controls="{{!canIUse}}">
<cover-view wx:if="{{canIUse}}">play</cover-view>
</video>
The data files for canIUse are updated with the base library, and developers are encouraged to test the new features in advance.
# Set the minimum base library version
Requires iOS 6.5.8 / Android 6.5.7 and above WeChat Home support
In order to facilitate developers to solve the problem that the lower version of the base library is not compatible with the new features of Weixin Mini Program, developers can set the minimum base library version requirements of the Mini Program.
Developers can login Weixin Mini Program management background, into the "settings - basic settings - basic library minimum version settings" configuration. Before configuration, developers can see the proportion of base library versions used by users who accessed the current Mini Program in nearly 30 days to help them understand current user usage.

After setting, if the user base library version is lower than the set value, Weixin Mini Program will not open properly and the user will be prompted to update the client version.
