All Products
Search
Document Center

Quick start

Last Updated: Jun 24, 2021
Note: Mini Programs are only supported in 10.1.60 and above baselines.

Prerequisites

You have accessed the project to mPaaS. For more information, see the following content:

Add the SDK

According to your access method, select the corresponding method to add the SDK.

  • Use CocoaPods-mPaaS plugin.
    This method is suitable for Access based on existing projects and using CocoaPods.
    1. In the Podfile, use mPaaS_pod "mPaaS_TinyApp" command to add Mini Program component dependency.
      1
    2. Execute pod install in the command line to complete the access.
Note: If you encounter problems during accessing the Mini Program, please search the group number 31591197 with DingTalk to join the Mini program question answering group for consultation.

Use the SDK

This section introduces the use of the SDK in combination with the official Demo of the Mini Program.

The process of using the Mini Program is mainly divided into the following three steps:

  1. Initialization configuration
  2. Release the Mini Program
  3. Start the Mini Program

1. Initialization configuration

When configuring the project, you need to:

If your App life cycle is not hosted by mPaaS framework, you also need to perform non-framework host configuration (if your baseline version is ≥ 10.1.68.25, we recommend that you use non-framework host configuration for 10.1.68.25 and later versions).

1.1 Initialize the container

Container initialization operations include starting the container, customizing the container, and updating the mini program package.

1.1.1 Start the container
  • In order to use the Nebula container, you need to call the SDK interface after the program is started to initialize the container. The initialization must be done in - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions of DTFrameworkInterface.

       
    1. - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    2. {
    3. // Initialize the container
    4. [MPNebulaAdapterInterface initNebula];
    5. }
  • If you need to use functions such as preset mini program packages, custom JSAPI and Plugin, please replace initNebula in the code above with the initNebulaWith interface in the code below, and pass in the corresponding parameters to initialize the container.

    • presetApplistPath: The package information path of a custom preset mini program package.
    • appPackagePath: The custom preset mini program package path.
    • pluginsJsapisPath: The storage path of custom JSAPI and Plugin files.

           
      1. - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
      2. {
      3. // Initialize the container
      4. NSString *presetApplistPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"MPCustomPresetApps.bundle/h5_json.json"] ofType:nil];
      5. NSString *appPackagePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"MPCustomPresetApps.bundle"] ofType:nil];
      6. NSString *pluginsJsapisPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Poseidon-UserDefine-Extra-Config.plist"] ofType:nil];
      7. [MPNebulaAdapterInterface initNebulaWithCustomPresetApplistPath:presetApplistPath customPresetAppPackagePath:appPackagePath customPluginsJsapisPath:pluginsJsapisPath];
      8. }
      Note: initNebula and initNebulaWithCustomPresetApplistPath are two parallel methods, do not call them at the same time.
  • Configure the Mini Program package request interval: mPaaS supports the configuration of the Mini Program package request interval, which can be configured globally or individually.

    • Global configuration: You can set the update frequency of mini program through the following code when initializing the container.
           
      1. [MPNebulaAdapterInterface shareInstance].nebulaUpdateReqRate = 7200;
      7200 is the value for setting the global update interval, 7200 is the default value, which represents the interval time, in seconds. You can modify this value to set your global mini program package request interval, the range is 0 ~ 86400 seconds (namely 0 ~ 24 hours, 0 means no request interval limitation).
    • Individual configuration: To configure only for the current Mini Program package. In the console, you can go to Add mini program package > Extended information and enter {“asyncReqRate”:”1800”} to set the request interval. For details, see the Extended information in Create a Mini Program package.
1.1.2 Customize the container

If necessary, you can customize the container configuration by setting the property value of MPNebulaAdapterInterface. The configuration must be set in - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions of DTFrameworkInterface, otherwise it will be overwritten by the container default configuration.

 
  1. - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. // Customize the container
  4. [MPNebulaAdapterInterface shareInstance].nebulaVeiwControllerClass = [MPH5WebViewController class];
  5. [MPNebulaAdapterInterface shareInstance].nebulaNeedVerify = NO;
  6. [MPNebulaAdapterInterface shareInstance].nebulaUserAgent = @"mPaaS/Portal";
  7. }

The meanings of the attributes are as follows:

Name Meaning Remarks
nebulaVeiwControllerClass Base class for HTML5 pages The default value is H5WebViewController. If you need to specify the base class of all HTML5 pages, you can directly set this interface.
Note: The base class must inherit from H5WebViewController.
nebulaWebViewClass Set the base class of WebView When the baseline version is greater than 10.1.60, the default value is H5WKWebView. The customized WebView must inherit from H5WKWebView.
When the baseline version is equal to 10.1.60, customization is not supported.
nebulaUseWKArbitrary Set whether to use WKWebView to load the mini program package page When the baseline version is greater than 10.1.60, the default value is YES.
When the baseline version is equal to 10.1.60, the default value is NO.
nebulaUserAgent Set the UserAgent of the application The set UserAgent will be added as a suffix to the default UA of the container.
nebulaNeedVerify Whether to verify or not, the default value is YES If the private key file is not uploaded when configuring the mini program package, this value must be set to NO, otherwise the loading of mini program package will fail.
nebulaPublicKeyPath Public key for mini program package verification The public key corresponding to the private key uploaded when configuring the mini program package.
nebulaCommonResourceAppList The appId list of the public resource package -
errorHtmlPath The HTML error page path displayed when HTML5 page fails to load MPNebulaAdapter.bundle/error.html is read by default.
configDelegate Set a custom switch delegate Provides the ability to globally modify the default switch value of the container.
1.1.3 Update mini program package

After the startup is complete, request all mini program package information, and check whether there is an update package on the server. In order not to affect the application launch speed, it is recommended to call after (void)application:(UIApplication \*)application afterDidFinishLaunchingWithOptions:(NSDictionary \*)launchOptions.

 
  1. - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
  2. {
  3. // Customize the container
  4. [MPNebulaAdapterInterface shareInstance].nebulaVeiwControllerClass = [MPH5WebViewController class];
  5. [MPNebulaAdapterInterface shareInstance].nebulaNeedVerify = NO;
  6. [MPNebulaAdapterInterface shareInstance].nebulaUserAgent = @"mPaaS/Portal";
  7. [MPNebulaAdapterInterface shareInstance].nebulaCommonResourceAppList = @[@"77777777"];
  8. // Update all mini program packages
  9. [[MPNebulaAdapterInterface shareInstance] requestAllNebulaApps:^(NSDictionary *data, NSError *error) {
  10. NSLog(@"");
  11. }];
  12. }

After initialization, the result is as follows:

1

1.2 Configure the Mini Program

1.2.1 Configure permissions

Configure the following App permissions in info.plist:

  • NSBluetoothAlwaysUsageDescription: Bluetooth permission (new permission in iOS 13).
  • NSCameraUsageDescription: Camera permission.
  • NSPhotoLibraryUsageDescription: Album permission.
  • NSLocationWhenInUseUsageDescription: Location permission.

01

1.2.2 Configure dynamic library

In TARGETS of the current project, add the FalconLooks library in General > Embedded Binaries.

Note:The configuration of the dynamic library has been cancelled in the 10.1.68.15 (included) and above baselines, and no configuration is required.

02

1.3 Non-framework host configuration

If the life cycle of your App is not hosted by the mPaaS framework, but instead is designated as a delegate defined by yourself, then you need additional configuration for non-framework host.

Note: If your baseline version is ≥ 10.1.68.25, we recommend that you use non-framework host configuration for 10.1.68.25 and later versions.

03

1.3.1 Start mPaaS framework

Call [[DTFrameworkInterface sharedInstance] manualInitMpaasFrameworkWithApplication:application launchOptions:launchOptions]; in the didFinishLaunchingWithOptions method of the current application to start the mPaaS framework.

Note: The framework startup must be called after window and navigationController of the current application are initialized, otherwise it will not take effect.
1.3.2 Create an application launcher

Create a subclass of DTBootLoader, override the createWindow and createNavigationController methods, and return the window and navigationControlle of the current application.

  • Set window: The keyWindow of the current application.
  • Set navigationController: The navigationController where the Mini Program is loaded, which must inherit from DFNavigationController.
    • If the rootviewcontroller of the current application keyWindow is a navigationController, just set it to this class;
    • If the rootviewcontroller of the current application keyWindow is a tabBarViewController, take the navigationController of the tab where the Mini Program is loaded.

05

06

Override the setupNavigationController method in the category of DTBootPhase to specify the navigationController loaded by the Mini Program.

07

08

1.3.3 Specify application launcher

Rewrite the method in the category of DTFrameworkInterface, specify the current application’s own bootloader, and hide the default window and launcher applications of the mPaaS framework.

09

1.4 Non-framework host configuration (10.1.68.25 and later versions)

This section introduces an easier way to initialize the mPaaS framework for non-framework host applications.

  • You only need to call the following methods after the application window and navigationController are created. There is no need to create bootloader, hide the frame window, etc.
    navigationController
  • Not inheriting DFNavigationController is supported.
    DFNavigationController
  • If the application has multiple navigation bars, and different offline packages need to be opened in different navigation bars, the navigation bar of the container needs to be reset after the navigation bar is switched.
    navigation bar

2. Release the Mini Program

Before starting the Mini Program, you need to release it through the mPaaS console.

2.1 Enter the Mini Program background

Log in to the mPaaS console, enter the target application, and go to the Mini Program > Release Mini Program page from the left navigation bar.

2.2 Configure virtual domain name

If you are using it for the first time, please configure the virtual domain name in Mini Program > Release Mini Program > Configuration management. The virtual domain name can be any domain name. It is recommended to use your enterprise domain name, such as test.com.

1

2.3 Create Mini program

Enter the mPaaS console and complete the following steps:

  1. Click Mini Program > Release Mini Program in the left navigation bar.
  2. On the Mini Program package list page, click New.
  3. In the New Mini Program window, enter the ID and the name of the Mini Program, and click OK. Among them, the Mini Program ID is a 16-digit number, such as 2018080616290001.
    1
  4. Under the Mini Program list, find the new created Mini Program and click Add.
    4
  5. In the Basic information column, complete the following configuration:
    • Version: Enter the version number of the Mini Program package, such as 1.0.0.0.
    • Client range: Select the minimum and maximum version of the iOS client of the App where the Mini Program is located. The client App within this range can start the corresponding Mini Program, otherwise it cannot be started. The minimum version can be 0.0.0, and the latest version can be left blank, which means that all versions of the client can start this Mini Program.
      Note: The version number here refers to the version number of the current client App, please refer to the Product Version field in the Info.plist of the project.
      13
    • Icon: Click Upload file to upload the icon of the Mini Program package. The icon must be uploaded when creating a Mini Program for the first time. Example icons are as follows:
      2
    • File: Upload the Mini Program package resource file, the file format is .zip. We have prepared an mPaaS sample Mini Program for you (click here to download), you can upload it directly.
      3
  6. In the configuration information area, complete the following configuration:
    • Main entry URL: Required, the homepage of the Mini Program package, such as /index.html#page/tabBar/component/index.
    • Keep other configurations as default.
      4
  7. Check The above information has been confirmed to be accurate and will not be modified after submission.
  8. Click Submit.

2.4 Release Mini Program

Enter the mPaaS console and complete the following steps:

  1. Click Mini Program > Release Mini Program in the left navigation bar.
  2. In the opened Mini Program package list page, select the Mini Program package and version you want to release, and click Create release.
    6
  3. In the Create release task area, complete the following configuration:
    • Release type: Select Official release type.
    • Release description: Optional.
  4. Click OK to complete the release creation.
    7

3. Start the Mini Program

After completing the above steps, when entering the corresponding page, call the startTinyAppWithId interface method provided by the framework to load the Mini Program.

 
  1. [MPNebulaAdapterInterface startTinyAppWithId:appId params:nil];

If you need to pass parameters when starting the Mini Program, you can set it through the param parameter. param contains two fields: page and query:

  • page: Used to specify the path to open a specific page.
  • query: Used to pass in custom parameters. Multiple key-value pairs are spliced with &.
 
  1. NSDictionary *param = @{@"page":@"pages/card/index", @"query":@"own=1&sign=1&code=2452473"};
  2. [MPNebulaAdapterInterface startTinyAppWithId:appId params:dic];