下载卡片资源
方法一:从控制台下载卡片文件,单击 bin 文件下载,下载后为 zip 文件。
方法二:本地打包卡片工程的 dist/main.zip。
命名资源
将下载的文件添加拷贝到资源文件中。
将下载的 Bin 文件重新命名为
卡片 ID@卡片版本,例如main@1_0_0_0.zip。
说明后期控制台将直接提供完整命名的 zip 包,无需用户手动修改命名,只需要添加到 assets 即可。
预置资源
Android
设置卡片引擎类
CubeEngineConfig的属性。/** * 存储模版的本地资源包的路径 * * @param resourcePath - 设置资源文件路径 */ public void setResourcePath(String resourcePath) { this.resourcePath = resourcePath; }设置本地蚂蚁动态卡片 assets 路径。
//清除卡片数据 CubeService.instance().destroyEngine(); CubeEngineConfig config = new CubeEngineConfig(); //设置路径 config.setResourcePath("您设置的资源所在路径"); CubeService.instance().initEngine(config, MainApplication.getApplication());将 zip 包放在 assets 中您设置的资源所在路径中。
iOS
将下载的文件添加到 Bundle 中。
新建 Bundle 文件,将下载的 Bin 文件压缩成 Zip 包,命名为
卡片 ID@卡片版本,例如main1@1_0_0_0.zip。此处的 JSON 文件为卡片所需要的数据,可以使用文件内置,也可以通过调用接口动态请求,根据自身需要选择数据来源方式。
将 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]; }
鸿蒙
设置卡片引擎类
CubeEngineConfig的属性。public setResourcePath(resourcePath: string): CubeEngineConfig public setResourcePaths(resourcePaths:Array<string>):CubeEngineConfig设置本地蚂蚁动态卡片 rawfile 的路径。
let resourcePaths: Array<string> = ["cube"] let config = CubeEngineConfig.obtain() .setResourcePath("mp") .setResourcePaths(resourcePaths) CubeEngine.getInstance().init(config)将 zip 包放置在 rawfile 下您设置的资源所在路径中。
该文章对您有帮助吗?