本文介绍如何基于已有工程使用 CocoaPods 接入内容中台 SDK。
添加 SDK
安装 Cocoapods-mPaaS 插件。执行以下命令进行安装:
sh <(curl -s http://mpaas-ios.oss-cn-hangzhou.aliyuncs.com/cocoapods/installmPaaSCocoaPodsPlugin.sh)
登录 mPaaS 控制台创建应用,并下载
.config
配置文件。更多信息,参见 在控制台创建应用。将
.config
配置文件拷贝到工程的根目录下(与Podfile
同级)。在命令行执行
pod mpaas init
命令,会自动处理Podfile
文件添加plugin
、source
以及mPaaS_baseline
配置。其中,需要将 baseline 信息手动修改为cp_change_33255
。在
Podfile
文件中,使用mPaaS_pod "mPaaS_MCMP"
添加内容中台组件依赖。执行
pod install
添加 mPaaS 依赖, 完成 SDK 接入。
使用 SDK
初始化配置
关闭 Bitcode 功能。
在
MPaaSInterface
的实现中通过userId
函数配置用户 ID。此 ID 为您当前应用用户的唯一标识,如手机号、邮箱等
调用 API
创建首页 Feed 流 View
调用以下接口创建首页 Feed 流 View,可将创建的 View 插入到需要的页面中。
//创建双列 Feed 流 View UIView *view = [[MPContentInterface shareInterface] createCubeCardFeedViewWithFrame:[UIScreen mainScreen].bounds feedType:MPContentFeedTypeCollectionView];
在内容社区 VC 中插入自定义的 View
支持在内容社区 Feed 流中插入自定义的广告位。
//创建内容社区 VC MPGroupFeedViewController *vc = [[MPContentInterface shareInterface] createFeedViewController]; //创建自定义 view UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 100)]; // 插入 view [[MPContentInterface shareInterface] insertCustomFeedView:view atIndex:5 toFeedViewController:vc];
点击商品“立即购买”的回调
点击商品时的回调接口,在此接口中可获取到商品的信息,如商品 ID、商品名称、跳转链接等。
//设置代理 [MPContentInterface shareInterface].delegate = self; //实现商品点击的代理方法 - (void)mpContentSelectedGoodsWithItemData:(id)itemData forType:(MPContentGoodsForType)type { NSString *productName = itemData.productName; UIViewController *vc = UIViewController.new; vc.title = productName; vc.view.backgroundColor = UIColor.whiteColor; [DTContextGet().navigationController pushViewController:vc animated:YES]; }
在图文详情页插入自定义 View
支持在图文详情页中,插入自定义的广告位。
//实现图文详情页插入自定义 View 的代理方法 - (void)insertCustomViewForRichTextDetailWithFeedData:(id)feedData contrainerView:(UIView *)contrainerView { // 或者图文详情信息 NSSTring *title = feedData.title; NSSTring *publishTime = feedData.publishTime; NSSTring *readCount = feedData.readCount; UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, 160)]; lab.backgroundColor = UIColor.redColor; lab.text = title; lab.textColor = UIColor.whiteColor; lab.numberOfLines = 0; lab.textAlignment = NSTextAlignmentCenter; lab.font = [UIFont systemFontOfSize:18]; [contrainerView addSubview:lab]; contrainerView.frame = lab.bounds; }
点赞未登录时回调
//点赞未登录时代理回调 - (void)mpContentIsLogin:(BOOL)isLogin { //to do }
反馈
- 本页导读 (0)
文档反馈