All Products
Search
Document Center

Mobile Platform as a Service:Manage offline packages

Last Updated:Jan 26, 2026

The performance of traditional online H5 pages is often affected by network conditions. To address this issue, you can package different services into an offline package and use the publishing platform to deliver updates to client resources.

This topic describes how to manage offline packages:

Prerequisites

Ensure that you have integrated NebulamPaaSBiz.framework into the client project after adding the SDK.

Generate an offline package

To generate an .amr offline package, build a frontend .zip package and then generate the .amr package online. For more information, see Generate an offline package.

Load an offline package

You can load an offline package in two ways, depending on whether the package is preset on the client:

Preset an offline package

Pages such as the home page or logon page must load quickly, regardless of network conditions. To achieve this, you can package these resources into an offline package and preset it in the project. This ensures that the resources load quickly even when the application is offline.

Perform the following steps:

  1. Create a separate bundle, such as DemoCustomPresetApps.bundle. Add the .amr offline package and the h5_json.json file downloaded from the publishing platform to this bundle.111

    Note

    The publishing platform currently supports downloading the h5_json.json configuration file for only a single offline package. If you are presetting multiple offline packages, you must manually merge them into the data array of the JSON file.

  2. When initializing the container, call the initNebulaWithCustomPresetApplistPath method and set the preset offline package path to the bundle that you created in the previous step.

     - (void)application:(UIApplication *)application beforeDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
     {
         // Initialize rpc
         [MPRpcInterface initRpc];
    
         // Initialize the container
         // [MPNebulaAdapterInterface initNebula];
    
         // Set the custom JSAPI path and preset offline package information
         NSString *presetApplistPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"DemoCustomPresetApps.bundle/h5_json.json"] ofType:nil];
         NSString *appPackagePath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"DemoCustomPresetApps.bundle"] ofType:nil];
         NSString *pluginsJsapisPath = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"DemoCustomPlugins.bundle/Poseidon-UserDefine-Extra-Config.plist"] ofType:nil];
         [MPNebulaAdapterInterface initNebulaWithCustomPresetApplistPath:presetApplistPath customPresetAppPackagePath:appPackagePath customPluginsJsapisPath:pluginsJsapisPath];
     }
  3. Similar to loading a non-preset offline package, call the method provided by the Nebula container to load the offline package when you enter the corresponding page.

     - (void)openPresetPackage {
         [[MPNebulaAdapterInterface shareInstance] startH5ViewControllerWithNebulaApp:@{@"appId":@"20180910"}];
     }

Load a remote offline package

In addition to presetting offline packages on the client, you can dynamically publish an offline package through the publishing platform. The client can then directly load the remote offline package. This prevents the client package from becoming oversized due to presetting too many offline packages.

Perform the following steps:

  1. After the application starts, preload the package information and download the offline package. This prevents a blank screen from appearing when the package is opened.

    • Interface methods

        @interface MPNebulaAdapterInterface : NSObject
      
        /**
         *  Request for a single application
         *
         *  @param params   The list of requests in {appid:version} format. You can pass multiple app IDs. The version number can have up to four segments, such as 1.0.0.1. If you do not specify a version, pass an empty value to use the latest version. Fuzzy matching is supported. For example, '*' matches the latest version, and '1.*' matches the latest version that starts with 1.
         *  @param finish   Completion callback
         */
        - (void)requestNebulaAppsWithParams:(NSDictionary *)params finish:(NAMRequestFinish)finish;
      
        @end
  2. After the client is configured, you can deliver an offline package through the publishing platform. For more information, see Real-time Release > Offline Package Management > Publish an offline package.

  3. When you enter the corresponding page, call the method provided by the Nebula container to load the offline package. The page will then use the offline package that was delivered from the publishing platform.

    • Sample code

        - (void)openPresetPackage {
        [[MPNebulaAdapterInterface shareInstance] startH5ViewControllerWithNebulaApp:@{@"appId":@"20180910"}];
        }
    • Interface method

        @interface MPNebulaAdapterInterface : NSObject
      
        /**
         *  Creates an H5 container based on the provided offline package information and automatically pushes to open it.
         *
         *  @param params The startup parameters for the H5 container. The appId parameter is required. For other optional parameters, see the document at https://tech.antfin.com/docs/2/85001.
         *
         */
        - (void)startH5ViewControllerWithNebulaApp:(NSDictionary *)params;
      
        @end

Use a global resource package

The Nebula global resource package prevents redundancy when multiple H5 applications use the same resources, such as the ReactJS framework code. By placing public resources into a global resource package, you can reduce the size of individual H5 applications. You can configure the global offline package in the afterDidFinishLaunchingWithOptions method, as shown in the following sample code. In this sample, 77777777 is the app ID of the global resource package.

The nebulaCommonResourceAppList property tells the H5 container to use the offline package with the specified ID as a global resource package. If you do not configure this ID, the package will not take effect, even if it is built-in.

```
- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [MPNebulaAdapterInterface shareInstance].nebulaCommonResourceAppList = @[@"77777777"];// Set the global resource package
}
```

To improve page loading speed, you should preset the global resource package. You can still deliver updates later through the H5 application backend.

Dynamically update an offline package

mPaaS provides powerful dynamic update capabilities. You can deliver a new version of an offline package through the publishing platform to update the corresponding page on the client. For more information, see Real-time Release > Offline Package Management > Publish an offline package.

Related links