All Products
Search
Document Center

SuperApp:Perform operations on miniapps

Last Updated:Oct 25, 2024

After you integrate the WindVane or uni-app miniapp container into a native app, you can search for miniapps, obtain a list of miniapps, or start a miniapp.

Obtain a list of miniapps

The miniapp container SDK provides an interface for obtaining a list of miniapps. If you only want to obtain the miniapp list, you can directly use this interface.

id<EMASMiniAppService> miniAppService = [[EMASServiceManager sharedInstance] serviceForProtocol:@"EMASMiniAppService"];

if (miniAppService) {
   // The default value of the anchor parameter is 0.
  [miniAppService getMiniAppList:anchor completionBlock:^(int resultCode, NSArray * _Nonnull miniApps, NSString *anchor) {
  	 // If the value of resultCode is 200, all miniapps are obtained.
     // Return a list of miniapps. By default, a maximum of 10 miniapps can be obtained. The anchor parameter is used to obtain more miniapps.
  }];
}

Search for miniapps

The miniapp container SDK provides an interface for searching for miniapps. If you only want to search for miniapps, you can directly use this interface.

id<EMASMiniAppService> miniAppService = [[EMASServiceManager sharedInstance] serviceForProtocol:@"EMASMiniAppService"];

if (miniAppService) {
   // The keyword parameter specifies the search keyword. The default value of the anchor parameter is 0.
  [miniAppService queryMiniApps:keyword anchor:anchor completionBlock:^(int resultCode, NSArray * _Nonnull miniApps, NSString *anchor) {
 		// If the value of resultCode is 200, the search is successful.	
    // Return the search results. By default, a maximum of 10 miniapps can be obtained. The anchor parameter is used to obtain more miniapps.
  }];
}

Start a miniapp

You can start a miniapp by using its ID. WindVane miniapps and uni-app miniapps can be started in the same manner. Loading a miniapp requires a specific period of time. We recommend that you add code to associated callback methods to initialize or update UI elements.

id<EMASMiniAppService> miniAppService = [[EMASServiceManager sharedInstance] serviceForProtocol:@"EMASMiniAppService"];

if (miniAppService) {
   [miniAppService openMiniApp:appId openConfiguration:nil completionBlock:^(int resultCode, NSDictionary * _Nonnull resultDict) {
            
    }];
}

Open a specific page within a miniapp

When you start a miniapp, you can configure the path parameter to open a specific page within the miniapp and use extraData to pass arguments to the page.

Note
  • For a uni-app miniapp, the path parameter specifies the absolute URL of the miniapp page and extraData is a JSON object used to pass startup arguments to the miniapp. After the miniapp is started, you can retrieve values from extraData by using the plus.runtime.arguments method.

  • To open a page within a WindVane miniapp, you can access a URL in the following format: https://{appId}.app.mini.windvane.suite.emas.alibaba.com/index.html#/{path}?key=value&key2=123. When you develop miniapps, you must use hash routing to handle the logic of page navigation.

id<EMASMiniAppService> miniAppService = [[EMASServiceManager sharedInstance] serviceForProtocol:@"EMASMiniAppService"];
    
if (miniAppService) {
    EMASMiniAppOpenConfiguration *config = [[EMASMiniAppOpenConfiguration alloc] init];
    if (path.length > 0) {
        // The deeplink path.
        config.path = path;
    }
    if (params){
        // The extended parameters.
        config.extraData = params;
    }
    
    [miniAppService openMiniApp:self.appId openConfiguration:config completionBlock:^(int resultCode, NSDictionary * _Nonnull resultDict) {
        NSLog(@"resultCode = %d, resultDict = %@",resultCode,resultDict);
        if (resultCode == 200) {
            // If the miniapp is started, you are redirected to the homepage of the miniapp.
        }
    }];
}

Obtain categoty list

The miniapp container SDK provides an interface for obtaining a category list of miniapps. If you only want to obtain the miniapp category list, you can directly use this interface.

id<EMASMiniAppService> miniAppService = [[EMASServiceManager sharedInstance] serviceForProtocol:@"EMASMiniAppService"];
    if (miniAppService) {
        [miniAppService queryMiniAppCategories:^(int resultCode, NSArray *resultArray) {
            if (resultCode == 200) {
               //If the value of resultCode is 200, category list are obtained.
            } else {
              //failed
               }
        }];
    }

Obtain miniapp list of the category

The miniapp container SDK provides an interface for obtaining a miniapp list of the category id. If you only want to obtain the miniapp list, you can directly use this interface.

id<EMASMiniAppService> miniAppService = [[EMASServiceManager sharedInstance] serviceForProtocol:@"EMASMiniAppService"];
   if (miniAppService) {
        [miniAppService queryMiniAppsByCategory:categoryId completionBlock:^(int resultCode, NSArray * _Nonnull resultArray) {
            if (resultCode == 200) {
                //If the value of resultCode is 200, miniapp list of the catgory id are obtained.
            } else {
               //failed
            }
        }];
    }