All Products
Search
Document Center

Mobile Platform as a Service:Mini program base library

Last Updated:Mar 24, 2021

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.

  1. if (my.getLocation) {
  2. my.getLocation();
  3. } else {
  4. // If you want users to experience your Mini program in the new version of client, you can use the following reminder.
  5. my.alert({
  6. title: 'Reminder',
  7. content: 'The current version is too low to use this feature. Please upgrade to the latest version.'
  8. });
  9. }

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:

  1. if (my.canIUse('getLocation.object.type')) {
  2. // Write your subsequent processing methods here
  3. } else {
  4. console.log('This parameter is not supported in the current version')
  5. }

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:

  1. if (my.canIUse('getSystemInfo.return.storage')) {
  2. // Write your subsequent processing methods here
  3. } else {
  4. console.log('The return value is not supported in the current version')
  5. }

Compatibility processing of component’s new properties

New properties of component cannot be implemented on earlier clients, but no error will be reported either. To downgrade the properties, see the following code:

  1. Page({
  2. data: {
  3. canIUse: my.canIUse('button.open-type.share')
  4. }
  5. })

Base library version

Base library version Corresponding baseline version
1.9.0 10.1.32 Download
1.14.1 10.1.60 Download

Description of base library integration

iOS

Base library integration is not needed in iOS.

Android

Due to the iteration of the baseline version, different baseline versions need to adopt different ways of integrating the base library. Before integrating the base library, please confirm your baseline version.

10.1.68.7 and later baseline versions

Set the Provider instance at startup. The code sample is as follows:

  1. H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(),new TinyAppCenterPresetProvider());
Note: 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

  1. Implment H5AppCenterPresetProvider interface class. The code sample is as follows:

    1. package com.mpaas.demo.nebula;
    2. import com.alipay.mobile.nebula.appcenter.H5PresetInfo;
    3. import com.alipay.mobile.nebula.appcenter.H5PresetPkg;
    4. import com.alipay.mobile.nebula.provider.H5AppCenterPresetProvider;
    5. import java.io.File;
    6. import java.io.InputStream;
    7. import java.util.HashMap;
    8. import java.util.HashSet;
    9. import java.util.Map;
    10. import java.util.Set;
    11. public class H5AppCenterPresetProviderImpl implements H5AppCenterPresetProvider {
    12. private static final String TAG = "H5AppCenterPresetProviderImpl";
    13. // Set the Mini-program-specific resource bundle. This ID is fixed, do no set to other values.
    14. private static final String TINY_COMMON_APP = "66666692";
    15. // The asset directory of preset packages
    16. private final static String NEBULA_APPS_PRE_INSTALL = "nebulaPreset" + File.separator;
    17. // Collection of preset packages
    18. private static final Map<String, H5PresetInfo> NEBULA_LOCAL_PACKAGE_APP_IDS = new HashMap();
    19. static {
    20. H5PresetInfo h5PresetInfo2 = new H5PresetInfo();
    21. // File name of build-in directory
    22. h5PresetInfo2.appId = TINY_COMMON_APP;
    23. h5PresetInfo2.version = "1.0.0.0";
    24. h5PresetInfo2.downloadUrl = "";
    25. NEBULA_LOCAL_PACKAGE_APP_IDS.put(TINY_COMMON_APP, h5PresetInfo2);
    26. }
    27. @Override
    28. public Set<String> getCommonResourceAppList() {
    29. Set<String> appIdList = new HashSet<String>();
    30. appIdList.add(getTinyCommonApp());
    31. return appIdList;
    32. }
    33. @Override
    34. public H5PresetPkg getH5PresetPkg() {
    35. H5PresetPkg h5PresetPkg = new H5PresetPkg();
    36. h5PresetPkg.setPreSetInfo(NEBULA_LOCAL_PACKAGE_APP_IDS);
    37. h5PresetPkg.setPresetPath(NEBULA_APPS_PRE_INSTALL);
    38. return h5PresetPkg;
    39. }
    40. /**
    41. * Set the ID of the resource bundle that can be downgraded
    42. */
    43. @Override
    44. public Set<String> getEnableDegradeApp() {
    45. return null;
    46. }
    47. @Override
    48. public String getTinyCommonApp() {
    49. return TINY_COMMON_APP;
    50. }
    51. @Override
    52. public InputStream getPresetAppInfo() {
    53. return null;
    54. }
    55. @Override
    56. public InputStream getPresetAppInfoObject() {
    57. return null;
    58. }
    59. }
  2. 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 is assets/nebulaPreset/66666692.

  3. Set the Provider instance at startup. The code sample is as follows:

    1. H5Utils.setProvider(H5AppCenterPresetProvider.class.getName(), new H5AppCenterPresetProviderImpl());
    Note :If 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.