Mini Program features depend on client support.
Interaction between base libraries and clients
Mini Program features depend on client support:
New features in a base library version require a specific minimum client version to run.
Some new features in later base library versions are not compatible with earlier client versions.
For more information about base library compatibility, see Ensure base library compatibility. You can use my.SDKVersion to check the current base library version number.
Compatible base libraries
Mini Program components and API features are continuously improved. Because older client versions do not support these new features, you must handle compatibility issues.
You can use the my.canIUse(String) interface to check for compatibility. For more information, see API reference.
Compatibility examples
Handle compatibility for new APIs
For new APIs, you can use the following code to determine whether the current base library supports the API:
if (my.getLocation) {
my.getLocation();
} else {
// Display a prompt to encourage users to upgrade to the latest client version.
my.alert({
title: 'Prompt',
content: 'The current version is too old to use this feature. Please upgrade to the latest version.'
});
}Handle compatibility for new API parameters
For new API parameters, you can use the following method to check for support and then add your handling code:
if (my.canIUse('getLocation.object.type')) {
// Add your handling code here.
} else {
console.log('The current version does not support this parameter')
}Handle compatibility for new API return values
For new API return values, you can use the following method to check for support and then add your handling code:
if (my.canIUse('getSystemInfo.return.storage')) {
// Add your handling code here.
} else {
console.log('The current version does not support this return value')
}Handle compatibility for new component properties
New component properties do not work on older client versions but do not cause errors. To implement graceful degradation for a property, see the following code:
Page({
data: {
canIUse: my.canIUse('button.open-type.share')
}
})Base library versions
Base library version | Base libraries and their baseline versions |
2.8.9 |
|
1.14.1 | 10.1.68 |
1.14.1 | 10.1.60 |
1.9.0 | 10.1.32 |
Base library integration guide
Different baseline versions require different integration methods. Before you integrate a base library, confirm your baseline version.
iOS
Baseline version 10.2.3
The Mini Program new container baseline cp_change_15200851 and 10.2.3 support the build of Mini Program Base Library 2.0.
It is recommended that the Mini Program new container prioritize using the baseline version 10.2.3.
Android
Baseline versions 10.1.68.7 and later
You can set the Provider instance at startup. The following code is an example:
H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(),new TinyAppCenterPresetProvider());If the client uses H5 public resource packages, you must inherit the TinyAppCenterPresetProvider class and merge the code related to the public resource packages into the instance of the inherited class.
Baseline versions in the 10.1.60 series and versions 10.1.68.6 and earlier
You can implement the
H5AppCenterPresetProviderinterface class. The following code is an example:package com.mpaas.demo.nebula; import com.alipay.mobile.nebula.appcenter.H5PresetInfo; import com.alipay.mobile.nebula.appcenter.H5PresetPkg; import com.alipay.mobile.nebula.provider.H5AppCenterPresetProvider; import java.io.File; import java.io.InputStream; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class H5AppCenterPresetProviderImpl implements H5AppCenterPresetProvider { private static final String TAG = "H5AppCenterPresetProviderImpl"; // Set the dedicated resource package for the Mini Program. This ID is fixed and cannot be changed. private static final String TINY_COMMON_APP = "66666692"; // The asset folder for the preset package. private final static String NEBULA_APPS_PRE_INSTALL = "nebulaPreset" + File.separator; // A collection of preset packages. private static final Map<String, H5PresetInfo> NEBULA_LOCAL_PACKAGE_APP_IDS = new HashMap(); static { H5PresetInfo h5PresetInfo2 = new H5PresetInfo(); // The file name in the built-in folder. h5PresetInfo2.appId = TINY_COMMON_APP; h5PresetInfo2.version = "1.0.0.0"; h5PresetInfo2.downloadUrl = ""; NEBULA_LOCAL_PACKAGE_APP_IDS.put(TINY_COMMON_APP, h5PresetInfo2); } @Override public Set<String> getCommonResourceAppList() { Set<String> appIdList = new HashSet<String>(); appIdList.add(getTinyCommonApp()); return appIdList; } @Override public H5PresetPkg getH5PresetPkg() { H5PresetPkg h5PresetPkg = new H5PresetPkg(); h5PresetPkg.setPreSetInfo(NEBULA_LOCAL_PACKAGE_APP_IDS); h5PresetPkg.setPresetPath(NEBULA_APPS_PRE_INSTALL); return h5PresetPkg; } /** * Sets the IDs of resource packages that can be degraded. */ @Override public Set<String> getEnableDegradeApp() { return null; } @Override public String getTinyCommonApp() { return TINY_COMMON_APP; } @Override public InputStream getPresetAppInfo() { return null; } @Override public InputStream getPresetAppInfoObject() { return null; } }Download the Mini Program base library that corresponds to the client's integrated version. Copy the base library to the
assetfolder specified in the previous step and rename it. Based on the code example in the previous step, the path for the Mini Program base library isassets/nebulaPreset/66666692.You can set the Provider instance at startup. The following code is an example:
H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(), new H5AppCenterPresetProviderImpl());NoteIf the client uses H5 public resource packages, you must merge the code related to the public resource packages into the instance class of
H5AppCenterPresetProvider.For more information, see Code examples.