文档

预置卡片

本文介绍了在 iOS 客户端中预置蚂蚁动态卡片的操作步骤。

前置条件

操作步骤

  1. 从控制台下载 Bin 文件。

    image.png
  2. 将下载的文件添加到 Bundle 中。

    新建 Bundle 文件,将下载的 Bin 文件压缩成 Zip 包,命名为 卡片 ID@卡片版本,例如 main1@1_0_0_0.zip。此处的 JSON 文件为卡片所需要的数据,可以使用文件内置,也可以通过调用接口动态请求,根据自身需要选择数据来源方式。

    image.png

    说明

    后期控制台将直接提供完整命名的 zip 包,无需用户手动修改命名,只需要添加到 Bundle 中即可。

  3. 将 Bundle 引入工程中,引擎初始化时传入 Bundle 路径。

    - (void)initEngine {
        //本地资源模板的 Bundle 路径
        NSString *bundlePath = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"MPCubeBundle.bundle"];
        CubeEngineConfig *config = [[CubeEngineConfig alloc] init];
        [config setBundlePath:bundlePath];
        [[CubeService sharedInstance] initWithConfig:config];
    }
  4. 加载预置卡片。

    CubeCardConfig *cardConfig = [[CubeCardConfig alloc] init];
    //设置卡片版本
    [cardConfig setVersion:@"1.0.0.0"];
    //设置卡片 ID
    [cardConfig setTemplteId:@"main1"];
    //预设卡片宽度
    [cardConfig setWidth:MP_Screen_Width];
    //预设卡片高度
    [cardConfig setHeight:CGFLOAT_MAX];
        
    NSString *mockBundlePath = [NSString stringWithFormat:@"%@/%@", [[NSBundle mainBundle] resourcePath], @"MPCubeBundle.bundle"];
    NSString *fullTplPath = [NSString stringWithFormat:@"%@/%@", mockBundlePath, @"mock1.json"];
    NSString *strData = [NSString stringWithContentsOfFile:fullTplPath encoding:NSUTF8StringEncoding error:nil];
    //设置卡片数据,此处为 Bundle 内置 Json 读取数据;也可以请求自身服务端接口获取数据,但要转换为 Json 字符串
    [cardConfig setData:[self dictionaryWithJsonString:strData]];
    //创建卡片
    [[CubeEngine sharedInstance] createCard:cardConfig callback:self];
  • 本页导读 (0)
文档反馈