# compatible
The functions of mini programs are constantly increasing, but the old version of WeChat client does not support the new functions, so it needs to be compatible when using these new capabilities.
Developers can make low version compatibility in the following ways:
# 1. Comparison of version numbers
WeChat client and Mini Program base library version number style Major.Minor.Patch (Major Revision Number. Minor Revision Number).
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 do this in the Mini Program by calling the [wx.getAppBaseInfo ]((wx.wx.getAppBaseInfo )) Gets the version number of the base library to which the current Mini Program is running. Run low version compatibility logic by version number comparison.
Version number comparison applies in all cases. Some scenarios can also be done using the methods mentioned below.
<=2.20.1 Please use the basic library 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' yes false of
Version number comparison can refer to 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 {
// If you want users to experience your Mini Program on the latest version of the client, you can prompt like this
wx.showModal({
title: "Hint,"
content: The current WeChat version is too low to use the function, please upgrade to the latest WeChat version and try again. '
})
}
# 2. API Judgment of existence
For the additional 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 {
// If you want users to experience your Mini Program on the latest version of the client, you can prompt like this
wx.showModal({
title: "Hint,"
content: The current WeChat version is too low to use the function, please upgrade to the latest WeChat version and try again. '
})
}
# 3. wx.canIUse
In addition to judging directly by the version number, it can also be determined by wx.canIUse To determine whether it can be used directly under the base library version. For example:
API Parameter or return value
for API The parameters or return value of the new parameters, can be determined using 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 are not processed on older versions, but they do not report errors. If a particular scenario requires some downgrading of an 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>
Nuff The data file is updated with the base library, and the new features in the new release may be missing, so developers are advised to test them in advance.
# Setting the minimum base library version
Need iOS 6.5.8 / Android 6.5.7 And above WeChat client support
In order to facilitate developers to solve the problem that the low version of the base library is not compatible with the new functions of the Mini Program, developers can set the minimum base library version requirements for the Mini Program.
Developers can log in to the Mini Program management background, enter theSet up - Basic settings - Base Library Lowest Version SettingsFor configuration. Before setting up, the developer can view the near 30 The proportion of base library versions used by users accessing the current Mini Program within three days to help developers understand the current user usage.
After setting, if the user base library version is lower than the set value, the Mini Program cannot be opened normally, and the user is prompted to update the client version.