The mini program capability requires the surrpot from client:
Relationship between the base library and the client
The Mini program capability requires the surrpot from client:
The new functions of each version of base library run on specific versions.
Some new functions of the high version base library are not compatible with low version clients.
See Compatible with base library for the method. You can check the version number of the current base library via my.SDKVersion
.
Compatible with base library
Currently, the Mini program components and API capabilities are gradually improved and enriched, but clients in the old versions do not support these new capabilities, so developers are advised to complete the corresponding compatibility processing.
You can implement compatibility judgment through the interface my.canIUse(String)
. For details, see Interface description.
Example of compatibility
Compatibility processing of new APIs
For new APIs, you can determine whether the current base library supports the API by the following codes.
if (my.getLocation) {
my.getLocation();
} else {
// If you want users to experience your Mini program in the new version of client, you can use the following reminder.
my.alert({
title: 'Reminder',
content: 'The current version is too low to use this feature. Please upgrade to the latest version.'
});
}
Compatibility processing of API new parameters
For new API parameters, you can determine whether they are supported by the following method, and write your subsequent processing methods:
if (my.canIUse('getLocation.object.type')) {
// Write your subsequent processing methods here
} else {
console.log('This parameter is not supported in the current version')
}
Compatibility processing of API new return values
For new API return values, you can determine whether they are supported by the following method, and write your subsequent processing methods:
if (my.canIUse('getSystemInfo.return.storage')) {
// Write your subsequent processing methods here
} else {
console.log('The return value is not supported in the current version')
}
Compatibility processing of component's new attributes
New attributes of component cannot be implemented on earlier clients, but no error will be reported either. To downgrade the attributes, see the following code:
Page({
data: {
canIUse: my.canIUse('button.open-type.share')
}
})
Base library version
Base library version | Corresponding baseline version |
2.8.9 |
|
1.14.1 | 10.1.68 |
1.14.1 | 10.1.60 |
1.9.0 | 10.1.32 |
Description of base library integration
Due to the iteration of baseline versions, different baseline versions require different ways to integrate the basic library. Before integrating the basic library, please confirm your baseline version.
iOS
10.2.3 baseline version
The new container baseline of Mini Program cp_change_15200851 supports the construction of Mini Program Basic Library 2.0.
Android
10.1.68.7 and later baseline versions
Set the Provider instance at startup. The sample code is as follows:
H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(),new TinyAppCenterPresetProvider());
If the H5 public resource package is used in the client, you need to inherit the TinyAppCenterPresetProvider
class and merge the related code of the public resource package into the instance of the inherited class.
10.1.60 series, 10.1.68.6 and earlier baseline versions
Implment
H5AppCenterPresetProvider
interface class. The code sample is as follows: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 Mini-program-specific resource bundle. This ID is fixed, do no set to other values. private static final String TINY_COMMON_APP = "66666692"; // The asset directory of preset packages private final static String NEBULA_APPS_PRE_INSTALL = "nebulaPreset" + File.separator; // Collection of preset packages private static final Map<String, H5PresetInfo> NEBULA_LOCAL_PACKAGE_APP_IDS = new HashMap(); static { H5PresetInfo h5PresetInfo2 = new H5PresetInfo(); // File name of build-in directory 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; } /** * Set the ID of the resource bundle that can be downgraded */ @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 corresponding Mini Program base library according to the version integrated in the client, copy the base library to the
asset
catalog specified in the previous step and rename it. Based on the code sample in the previous step, the base library path of the Mini Program isassets/nebulaPreset/66666692
.Set the Provider instance at startup. The code sample is as follows:
H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(), new H5AppCenterPresetProviderImpl());
NoteIf the H5 public resource package is used in the client, please merge the relevant code of the public resource package into the instance class of the
H5AppCenterPresetProvider
.For more information, Please refer to the Get code sample.