Ant Cube Card (hereinafter referred to as Cube Card) originated from the demand for dynamic native pages, and the product form is Cube Card. With the emergence of the Mini Program concept, Cube Card have been integrated into the Alipay Mini Program technology stack, and the product form is a lightweight Alipay Mini Program solution (as opposed to web Mini Program that are centered on browsing).
Ant Cube Card supports three integration methods: integrate based on mPaaS framework, integrate based on existing projects and using mPaaS plugins, and integrate based on existing projects and using CocoaPods. This topic describes how to integration Ant Cube Card and use Ant Cube Card.
Prerequisites
You have integrated the project into mPaaS. For more information, see the following:
The Cube card tool AntCubeTool is already installed. For more details, please refer to About AntCubeTool.
Procedure
Select a baseline.
Add a primary baseline 10.2.3.
Add Cube Card component.
Initialize the card.
Build a card project.
Initialize the project.
Construct project.
Release a card.
Go to the Ant Cube Card platform.
Create a card.
Add card resources.
Release the card.
Render the card.
Select baseline.
Cube Card is now supported in the primary baseline 10.2.3. Please select the appropriate component addition method based on your integration method.
Use mPaaS Xcode Extension
This method is applicable to integration methods: Integrate based on mPaaS framework or Integrate by using mPaaS plugin based on existing projects.
Click the Xcode menu item Editor > mPaaS > Edit Project > Upgrade Baseline to switch the project to the 10.2.3 baseline.
NoteIf the "Upgrade Baseline" option is not clickable, please ensure that the project configuration has been imported. Refer to the Prerequisites section to open the project editing page.
After upgrading the baseline, click Edit Module > Modify Module, select the Cube Card, save, and then click Start Editing to complete the addition.
Use cocoapods-mPaaS Plugin
This method is suitable for integration method: Integrate by using CocoaPods based on the existing project.
Perform the following operations in the Podfile.
Change mPaaS_baseline to
10.2.3.Use mPaaS_pod "mPaaS_Cube" to add the Cube Card component dependency.
Simply run
pod installto complete the integration.
Initialize the card.
Compile the Xcode project. If the header file cannot be found, turn on the option to set the
Allow Non-modular Includes In Framework ModulestoYes, as shown in the following figure.
Add system dependencies.

Import the libraries required for Cube Card.
#import <CubeCrystal/CubeEngine.h> #import <AntCube/CubeService.h>Use a singleton to initialize the card engine.
- (void)initEngie{ static dispatch_once_t onceToken; NSString *mockBundlePath = [NSString stringWithFormat:@"%@/%@/crystal", [[NSBundle mainBundle] resourcePath], @"MPCubeDemo.bundle"]; dispatch_once(&onceToken, ^{ CubeEngineConfig* config = [[CubeEngineConfig alloc] init]; [config setBundlePath:mockBundlePath]; [[CubeService sharedInstance] initWithConfig:config]; }); }
Build a card project.
Initialize a project. Execute
act initcommand in the terminal.Select Application Type as Cube and select Template Card (VUE format).
Enter an application name. Enter a name for your project. We recommend that you use a combination of English, numbers, and underscores.
Please select "Create an additional project source code folder". This will create an additional folder named after the application. If you select "Do not", the project will be initialized directly in the current directory.
Construct the project. Run the
cdcommand to open the created card project and run theact buildto complete the construction. The constructed product will be in the/dist/folder of your project.
Release the card.
Go to the Ant Cube Card platform.
Click Create Card.
We recommend that you use a combination of English, numbers, and underscores for the card ID. The client will rely on the card ID when rendering the card. The card name can take any value.
Add card resources.
We recommend that you use a 4-digit version number.
Select the main.zip that you just compiled.
The client range refers to the client version that can be pulled to the card. If you want to overwrite all client versions, enter
0.0.0.0in the minimum version field.
Release the card.
Click Create Release.
Select Official Release.
After the card is released, the client can pull the card.
Render the card.
Copy the card ID and card version number from the webpage.
//Create card object. CubeCardConfig *cardConfig = [[CubeCardConfig alloc] init]; //Configure the card version (required), copied from the console. [cardConfig setVersion:@"1.0.0.0"]; //Configure card ID (required), copy from console. [cardConfig setTemplteId:@"20211118"]; //Preset card width. [cardConfig setWidth:[UIScreen mainScreen].bounds.size.width]; //Preset card height. [cardConfig setHeight:350]; //Set the card data (required) parameter to business JSON data. [cardConfig setData:@{}]; //Load the card. [[[CubeService sharedInstance] getEngine] createCard:cardConfig callback:self];The card retrieves the key "iosImage", and will then obtain the value corresponding to the key "iosImage", as shown in the following code:
[self.cardConfig setData:@{@"iosImage":@"https://img.zcool.cn/community/013edb5c7b5b1ca801213f269fc887.jpg@1280w_1l_2o_100sh.jpg"}];The delegate method after card creation needs to conform to the
CCardCallbackdelegate protocol and implement theonLoaded:cardType:config:erroCodeprotocol method.@interface ViewController () <CCardCallback> @end- (void)onLoaded:(CubeCard *)card cardType:(CCardType)cardType config:(CubeCardConfig *)config erroCode:(CubeCardResultCode)erroCode { //Card creation failed if (!card) { NSLog(@"load card fail %@ style %d error %d", [config templteId], cardType, erroCode); return; } //Creation successful NSLog(@"load card success %@ style %d error %d", [config templteId], cardType, erroCode); dispatch_async(dispatch_get_main_queue(), ^{ //Main thread UI operations: Rendering cards CubeView *view = [[[CubeService sharedInstance] getEngine] createView]; CGSize size = [card getSize]; [view setFrame:CGRectMake(0, 20, size.width, size.height) ]; [self.view addSubview:view]; [card renderView:view]; }); }Build & Run.
If compilation and execution are successful, the Xcode command line may report an RPC request exception. For details, please refer to RPC request exception.
Effect preview.
Demo Reference
If you need to refer to the demo of this integration method, please click: MPCubeDemo_Pod.zip.