Getting Started

更新时间:
复制 MD 格式

Note

Mini Programs are supported only in baselines 10.1.60 and later.

Prerequisites

Your project is now integrated with mPaaS. For more information, see the following:

Add the SDK

Choose the appropriate method based on your connection type.

  • Use the mPaaS Xcode Extension. This method applies if you connected your project using the Connect using the mPaaS framework or Connect an existing project using the mPaaS plugin method.

    1. In Xcode, choose Editor > mPaaS > Edit Project to open the project editing page.

    2. Select Mini Program, save the settings, and then click Start Editing to add the SDK.2

  • Use the cocoapods-mPaaS plugin. This method applies if you connected your project using the Connect an existing project using CocoaPods method.

    1. In the Podfile, add the mPaaS_pod "mPaaS_TinyApp" dependency for the Mini Program component.1

    2. From the command line, run pod install to complete the connection.

    Note

    If you have questions about the connection, you can search for and join the DingTalk group with the ID 145930007362. This group includes the mPaaS public cloud Q&A assistant, which can answer common questions about the connection process. For more information about the assistant, see Public cloud Q&A assistant.

Use the SDK

This topic describes how to use Mini Programs with the official Mini Program demo.

The process of using a Mini Program involves three main steps:

  1. Initialize configurations

  2. Publish the Mini Program

  3. Start the Mini Program

1. Initialize configurations

Project configuration involves the following steps:

  • Initializing the container

  • Configuring the Mini Program

If the mPaaS framework does not manage your app's lifecycle, you must perform additional configurations. If you are using baseline 10.1.68.25 or later, follow the instructions for non-framework management for versions 10.1.68.25 and later.

1.1 Initialize the container

Container initialization includes starting the container, customizing the container, and updating the Mini Program package.

1.1.1 Start the container

  • To use the Nebula container, you must call the SDK interface to initialize it after the application launches. This initialization must occur in the DTFrameworkInterface - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions method.

    - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        // Initialize the container
        [MPNebulaAdapterInterface initNebula];
    }
  • To use features such as preset Mini Program packages, custom JSAPIs, and Plugins, use the initNebulaWith interface instead of the initNebula interface. Pass the required parameters to initialize the container.

    • presetApplistPath: The path of the package information for the custom preset Mini Program package.

    • appPackagePath: The path of the custom preset Mini Program package.

    • pluginsJsapisPath: The storage path for custom JSAPI and Plugin files.

        - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
        {
            // Initialize the container
            NSString *presetApplistPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"MPCustomPresetApps.bundle/h5_json.json"] ofType:nil];
            NSString *appPackagePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"MPCustomPresetApps.bundle"] ofType:nil];
            NSString *pluginsJsapisPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"Poseidon-UserDefine-Extra-Config.plist"] ofType:nil];
            [MPNebulaAdapterInterface initNebulaWithCustomPresetApplistPath:presetApplistPath customPresetAppPackagePath:appPackagePath customPluginsJsapisPath:pluginsJsapisPath];
        }
      Note

      The initNebula and initNebulaWithCustomPresetApplistPath methods are mutually exclusive. Do not call both methods.

  • mPaaS lets you configure the request interval for Mini Program packages. You can set this interval globally or for a single package.

    • Global configuration: Use the following code to set the update frequency for Mini Program packages when you initialize the container.

      [MPNebulaAdapterInterface shareInstance].nebulaUpdateReqRate = 7200;

      In the code, 7200 is the global update interval in seconds. You can change this value to set a different global request interval. The valid range is 0 to 86,400 seconds (0 to 24 hours). A value of 0 indicates that there is no limit on the request interval.

    • Single package configuration: To configure the interval for a single package, navigate to Add Mini Program Package > Extended Information in the console. Enter {"asyncReqRate":"1800"} to set the request interval. For more information, see the Extended Information section in Create a Mini Program package.

1.1.2 Customize the container

You can customize the container configuration by setting the properties of MPNebulaAdapterInterface as needed. You must set these properties in the DTFrameworkInterface - (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions method. Otherwise, the default container configurations will overwrite your custom settings.

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

The properties are described as follows:

Name

Description

Notes

nebulaViewControllerClass

Specifies the base class for H5 pages.

The default value is `H5WebViewController`. To specify a base class for all H5 pages, set this property directly. Note: The custom base class must inherit from `H5WebViewController`.

nebulaWebViewClass

Specifies the base class for WebView.

For baselines later than 10.1.60, the default is `H5WKWebView`. A custom WebView must inherit from `H5WKWebView`. This property cannot be customized in baseline 10.1.60.

nebulaUseWKArbitrary

Specifies whether to use `WKWebView` to load Mini Program package pages.

The default value is `YES` for baselines later than 10.1.60 and `NO` for baseline 10.1.60.

nebulaUserAgent

Specifies the User-Agent for the application.

The specified User-Agent is appended as a suffix to the container's default User-Agent.

nebulaNeedVerify

Specifies whether to perform signature verification. The default value is `YES`.

If you did not upload a private key file when you configured the Mini Program package, you must set this value to `NO`. Otherwise, the Mini Program package will fail to load.

nebulaPublicKeyPath

Specifies the public key for Mini Program package signature verification.

This must be the public key that corresponds to the private key you uploaded when you configured the Mini Program package.

nebulaCommonResourceAppList

Specifies the list of app IDs for public resource packages.

-

errorHtmlPath

Specifies the path of the HTML error page to display when an H5 page fails to load.

By default, the system reads the MPNebulaAdapter.bundle/error.html file.

configDelegate

Setting the custom switch delegate

Allows you to globally modify the default switch values of the container.

1.1.3 Update the Mini Program package

After the application starts, you should request all Mini Program package information to check for updates on the server-side. To avoid affecting the application's startup speed, make this call after the (void)application:(UIApplication \*)application afterDidFinishLaunchingWithOptions:(NSDictionary \*)launchOptions method.

- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Customize the container
    [MPNebulaAdapterInterface shareInstance].nebulaVeiwControllerClass = [MPH5WebViewController class];
    [MPNebulaAdapterInterface shareInstance].nebulaNeedVerify = NO;
    [MPNebulaAdapterInterface shareInstance].nebulaUserAgent = @"mPaaS/Portal";
    [MPNebulaAdapterInterface shareInstance].nebulaCommonResourceAppList = @[@"77777777"];
    // Update all Mini Program packages
    [[MPNebulaAdapterInterface shareInstance] requestAllNebulaApps:^(NSDictionary *data, NSError *error) {
        NSLog(@"");
    }];
}

In your project, navigate to TARGETS > General > Embedded Binaries and add the FalconLooks library.

Note

  • Configuring the dynamic library is no longer required for baselines 10.1.68.15 and later.

  • In the Xcode Extension, you can choose mPaaS > Edit Project > Edit Module to view the baseline version number on the right side of the Project Module Information section.

02

1.2 Non-framework management configurations (for versions 10.1.68.25 and later)

This section describes a simple method to initialize the mPaaS framework for non-framework-managed applications.

  • Call the following method after the application's window and navigationController are created. You no longer need to create a bootloader or hide the framework's window.navigationController

  • Inheriting from DFNavigationController is not required.DFNavigationController

  • If the app has multiple navigation bars and you need to open different offline packages in different navigation bars, you must reset the container's navigation bar after switching navigation bars.

1.3 Non-framework-managed configuration

If your app's lifecycle is managed by your own custom delegate instead of the mPaaS framework, you must perform additional configurations for non-framework management.

Note

If you are using baseline 10.1.68.25 or later, follow the instructions for non-framework management for versions 10.1.68.25 and later.

03

1.3.1 Start the mPaaS framework

In your application's didFinishLaunchingWithOptions method, call [[DTFrameworkInterface sharedInstance] manualInitMpaasFrameworkWithApplication:application launchOptions:launchOptions]; to start the mPaaS framework.

Note

You must start the framework after the application's window and navigationController are initialized. Otherwise, the start command will not take effect.

1.3.2 Create an application launcher

Create a child class of DTBootLoader and overwrite the createWindow and createNavigationController methods to return your application's window and navigationController.

  • Set window: The keyWindow of your application.

  • Set navigationController: The navigationController where the Mini Program will be loaded. It must inherit from DFNavigationController.

    • If the rootViewController of your application's keyWindow is a navigationController, set it to that class.

    • If the rootViewController of your application's keyWindow is a tabBarViewController, use the navigationController of the tab where the Mini Program will be loaded.

0506

In the DTBootPhase category, overwrite the setupNavigationController method to specify the navigationController for loading the Mini Program.07081.3.3 Specify the application launcher

In the DTFrameworkInterface category, overwrite the method to specify your application's bootloader and hide the default window and launcher of the mPaaS framework.09

2. Publish the Mini Program

Before you can start the Mini Program, you must publish it from the mPaaS console.

2.1 Go to the Mini Program backend

Log on to the mPaaS console, navigate to the target application, and then choose Mini Program > Mini Program Release from the navigation pane on the left.

2.2 Configure a virtual domain name

If this is your first time using this feature, you must first configure a virtual domain name. To do this, navigate to Mini Program > Mini Program Release > Configuration Management. The virtual domain name can be any domain name, but we recommend using your company's domain name, such as example.com.

Note

You must use a domain name that you have registered.

2.3 Create a Mini Program

In the mPaaS console, complete the following steps:

  1. From the navigation pane on the left, choose Mini Program > Mini Program Release.

  2. On the Mini Program package list page that appears, click Create.

  3. In the Create Mini Program window, enter the Mini Program ID and Mini Program Name, and then click OK. The Mini Program ID can be any 16-digit number, such as 2018080616290001. 1

  4. In the Mini Program list, find the new Mini Program and click Add.

  5. In the Basic Information section, complete the following configurations:

    • Version: Enter the version number of the Mini Program package, such as 1.0.0.0.

    • Client Scope: Select the minimum and maximum versions of the iOS client for the Mini Program. Client apps within this version range can start the Mini Program. Otherwise, the Mini Program cannot be started. For example, you can enter 0.0.0 for the minimum version and leave the maximum version blank. This configuration allows all client versions to start this Mini Program.

      Note

      The version number refers to the version of your client app, which is specified in the Info.plist Product Version field.

      13

    • Icon: Click Select File to upload an icon for the Mini Program package. You must upload an icon when you create a Mini Program for the first time. An example icon is shown below:2

    • File: Upload the Mini Program package resource file. The file must be a .zip file. You can download a sample mPaaS Mini Program and upload it directly.

      3

  6. In the Configuration Information section, complete the following configurations:

    • Main Entry URL: Required. Enter the path to the homepage of the Mini Program package, such as /index.html#page/tabBar/component/index.

    • Keep the default values for other configurations.

      4

  7. Select I have confirmed that the above information is accurate and will not be modified after submission.

  8. Click Submit.

2.4 Publish the Mini Program

In the mPaaS console, complete the following steps:

  1. From the navigation pane on the left, choose Mini Program > Mini Program Release > Official Mini Program Package Management.

  2. On the Mini Program package list page that appears, select the Mini Program package and version that you want to publish, and then click Create Release. 6

  3. In the Create Release Task pane, complete the following configurations:

    • Release Type: Select the Official release type.

    • Release Description: Optional.

  4. Click OK to create the release.

3. Start the Mini Program

After you complete the preceding steps, call the framework's startTinyAppWithId interface method to load the Mini Program when the user navigates to the corresponding page.

[MPNebulaAdapterInterface startTinyAppWithId:appId params:nil];

To pass parameters when you open the Mini Program, you can use the param parameter. The param parameter contains two fields: page and query:

  • page: Specifies the path to a specific page that you want to open.

  • query: Passes custom parameters. Multiple key-value pairs are concatenated with an ampersand (&).

NSDictionary *param = @{@"page":@"pages/card/index", @"query":@"own=1&sign=1&code=2452473"};
[MPNebulaAdapterInterface startTinyAppWithId:appId params:dic];