All Products
Search
Document Center

SuperApp:Integrate a miniapp container into a native app

Last Updated:Oct 17, 2024

Enterprise Mobile Application Studio (EMAS) allows you to integrate the WindVane or uni-app miniapp container into a native app. This topic describes how to integrate a miniapp container into an iOS app.

Prerequisites

  • The AccessKey, SecretKey, and App Code of a native app are obtained. For more information, see the Configure an app topic in the Application Open Platform (for platform operators) chapter of the User Guide.

  • The domain name of Application Open Platform is obtained. The domain name of the demo environment is poc.superapp-intl.com.

Step 1: Add dependencies

  1. Add CocoaPods repository.

    pod repo add superapp-intl-emas-ios-emas-specs https://gitlab-console.superapp-intl.com/emas-ios/emas-specs.git

    pod repo add superapp-intl-emas-ios-emas-specs-thirdpart https://gitlab-console.superapp-intl.com/emas-ios/emas-specs-thirdpart.git
  2. In the Podfile located in the project root directory, configure the CocoaPods repository.

    SDKs for miniapp containers are available in the CocoaPods repository. For information about the account, and password, contact the O&M engineer.

    source 'https://gitlab-console.superapp-intl.com/emas-ios/emas-specs.git'
    source 'https://gitlab-console.superapp-intl.com/emas-ios/emas-specs-thirdpart.git'
  3. In the Podfile located in the project root directory, add the dependencies for the miniapp container.

    use_frameworks!
    // The basic SDK for the miniapp container. This dependency is required for both WindVane and uni-app.
    pod 'EMASServiceManager'
    pod 'EMASMiniAppAdapter'
    // The SDK for the WindVane miniapp container. If you want to integrate the WindVane miniapp container into the app, include this dependency. 
    pod 'EMASWindVaneMiniApp'
    // The SDK for the uni-app miniapp container. If you want to integrate the uni-app miniapp container into the app, include this dependency. 
    pod 'EMASUniappMiniApp'

Step 2: Initialize the container

You must initialize the miniapp container before you can use it.

// The SDK that is used to initialize the miniapp container.
EMASMiniAppInitConfig *miniAppInitConfig = [EMASMiniAppInitConfig new];
miniAppInitConfig.useUniApp = YES;
miniAppInitConfig.useWindVane = YES;
miniAppInitConfig.accessKey = @"ZXZ8****";//Obtain the AccessKey from Application Open Platform.
miniAppInitConfig.secretKey = @"3PNJxKtf7/eqUohlG3bI****";//Obtain the SecretKey from Application Open Platform.
miniAppInitConfig.host = @"emas.example.com";//Specify the domain name of Application Open Platform. The value in this sample code is provided for reference only. The domain name of the demo environment is emas-publish-intl.emas-poc.com. 
miniAppInitConfig.appCode = @"161160615860445224****";//Obtain the App Code from Application Open Platform.

EMASMiniAppServiceImpl *miniAppService = [EMASMiniAppServiceImpl new];
[miniAppService initialize:miniAppInitConfig];
[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASMiniAppService" IMPClass:@"EMASMiniAppServiceImpl" target:miniAppService];

// The following code provides an example of optional initialization configurations for the WindVane miniapp container. If you want to use favorites or associated users or intercept URLs or upload images, please implement the corresponding classes. 
//[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASMiniAppFavoriteService" IMPClass:@"EMASMiniAppFavoriteServiceImpl" target:[EMASMiniAppFavoriteService new]];//favorite
//[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASUserInfoService" IMPClass:@"EMASUserInfoServiceImpl" target:[EMASUserInfoServiceImpl new]];//associated users
//[[EMASServiceManager sharedInstance] registerServiceProtocol:@"EMASMiniAppURLService" IMPClass:@"EMASMiniAppURLServiceImpl" target:[EMASMiniAppURLServiceImpl new]];// intercept URLs

Note

  1. Using a Mac computer with Apple Silicon M series chips and running with the simulator, the simulator needs to select with the Rosetta label.

    Install Rosetta:

    sudo softwareupdate --install-rosetta --agree-to-license

    Running without Rosetta, the error Building for 'iOS-simulator', but linking in object file needs to be modified in Build Settings -> Excluded Architectures, add Any iOS Simulator SDK arm64. The third-party .framework or .a error x86_64 Undefined symbol:_OBJC_CLASS_$_ needs to be added in the project's build setting -> Other linker flags -ld64, then select the simulator marked with Rosetta in Product -> Destination to run the project.

  2. Added ENABLE_USER_SCRIPT_SANDBOXING in Xcode15. If you get an error "Sandbox: rsync.samba deny", change build setting -> user script sandboxing to No.

API reference

For more information, see API referenece.