# Compatibility
New Mini Program features are constantly being released, but are not supported for older Weixin app versions. Therefore, compatibility should be addressed when using these new features.
Developers can use the following methods to ensure compatibility with older versions:
# 1. Version Comparison
Weixin app and Mini Program base library versions are expressed in the format Major.Minor.Patch (major version number.minor version number.patch version number).
In the documentation, the minimum base library versions are specified for the features described in component, API, and other pages.
In a Mini Program, developers can call wx.getSystemInfo]((wx.getSystemInfo)) or [wx.getSystemInfoSync to get the version of the base library run by the Mini Program. The version comparison method is used to run a lower version for compatibility purposes.
Version comparison can be used in any circumstance. In some cases, you can also use the methods discussed below.
Note: Do not compare versions by directly comparing the strings.
See the sample code below:
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.getSystemInfoSync().SDKVersion
if (compareVersion(version, '2.3.0') >= 0) {
wx.startGyroscope()
} else {
// If you want users to experience the Mini Program in the latest app, you can display a prompt like this:
wx.showModal({
title: 'Prompt',
content: 'You cannot use this feature due to a low Weixin version. Upgrade to the latest Weixin version and try again.'
})
}
# 2. API Existence Judgment
For a new API, you can judge the existence of the API to determine if a user’s base library is supported. For example:
if (wx.startGyroscope) {
wx.startGyroscope()
} else {
// If you want users to experience the Mini Program in the latest app, you can display a prompt like this:
wx.showModal({
title: 'Prompt',
content: 'You cannot use this feature due to a low Weixin version. Upgrade to the latest Weixin version and try again.'
})
}
# Setting Minimum Base Library Version
Supported in Weixin 6.5.8 for iOS/Weixin 6.5.7 for Andriod and later
To easily solve the incompatibility of older base library versions with new Mini Program features, developers can set minimum base library version requirements.
Developers can log in to the Mini Program admin console and go to Settings > Basic Settings > Set Minimum Base Library Version. Before configuration, developers should look at the proportion of different base library versions used by users who have accessed the Mini Program in the past 30 days.
After the minimum version is set, if a user's base library version is lower than the set value, the user will not be able to access the Mini Program and will be prompted to update the Weixin app.