使用 SDK
初始化 SDK
在 AppDelegate
的 -application:didFinishLaunchingWithOptions:
方法中,对ICDP SDK
进行初始化。
注意:
TMFICDP
使用QAPM
的统计模块对广告数据进行统计上报,如果需要单独使用 QAPM,在install
方法初始化 SDK后,根据业务情况调用QAPM
自行上报。
Objective-C
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[ICDPManager sharedManager].appId = @"appId";
[ICDPManager sharedManager].userId = @"test";
[ICDPManager sharedManager].athenaHost = @"athenaHost";
[ICDPManager sharedManager].adHost = adHost;
[ICDPManager sharedManager].deviceID = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
[ICDPManager sharedManager].customerAppVersion = @"1.0.0";
return YES;
}
Swift
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let manager = ICDPManager.shared()
manager.appId = "app-i7fqlbh8s0"
manager.adHost = "http://193.112.44.156:18080"
manager.install()
return true
}
接入广告视图
在 ViewController
实例的生命周期中,需要实现投放监听协议ICDPManagerDelegate
,在viewDidLoad
方法中调用添加监听方法,当投放数据和视图就绪后,通过回调方法进行视图添加和数据处理,最后,在dealloc
方法中调用移除监听方法。
接口定义
Objective-C
+ (void)addObserver:(id<ICDPManagerDelegate>) observer
forViewIDs:(NSArray<NSString *> *) viewIDs
forDataIDs:(NSArray<NSString *> *) dataIDs;
参数说明
参数 | 类型 | 描述 | 必选 |
---|---|---|---|
observer | ICDPManagerDelegate | 观察者 | Y |
viewIDs | NSArray |
需要监听 View 加载的展位 ID 数组 | Y |
dataIDs | NSArray |
需要监听 Data 加载的展位 ID 数组 | N |
+ (void)removeObserver:(id<ICDPManagerDelegate>)observer;
参数说明
参数 | 类型 | 描述 | 必选 |
---|---|---|---|
observer | ICDPManagerDelegate | 观察者 | Y |
- (void)adViewDidFinishLoading:(ICDPADView *)adView identifer:(NSString *) identifier;
参数说明
参数 | 类型 | 描述 | 必选 |
---|---|---|---|
adView | ICDPADView | 广告视图 | Y |
identifier | NSString | 展位 ID | Y |
广告样式定义
typedef NS_ENUM(NSInteger, ICDPADStyle) {
ICDPADStyleCarousel, //轮播
ICDPADStyleSingle, //单图
ICDPADStyleNotice, //公告
ICDPADStylePopup, //弹窗
ICDPADStyleImageAndText,//图文
};
代码示例
Objective-C
@interface ViewController ()<ICDPManagerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
//添加投放监听
NSArray *codeArr = @[@"test1",@"test2",@"test3",];
[[ICDPManager addObserver:self forViewIDs:codeArr forDataIDs:nil];
}
// 实现协议回调
- (void)adViewDidFinishLoading:(ICDPADView *)adView identifier:(NSString *) identifer {
//将获取的adview添加展示,identifer为广告ID
if (!adView) {
return;
}
ICDPADStyle style = adView.adStyle;
switch (style) {
case ICDPADStyleSingle:
[self.view addSubview:adView];
break;
case ICDPADStyleNotice:
[self.view addSubview:adView];
break;
case ICDPADStyleCarousel:
[self.view addSubview:adView];
break;
default:
break;
}}
}
- (void)dealloc {
[ICDPManager removeObserver:self];
}
@end
广告样式示例
接入闪屏广告
使用广告 ID 创建 ICDPSplashView
实例,调用show
方法。闪屏广告采用离线加载模式,即第一次请求数据时候会先缓存广告图片,并不会显示闪屏。
接口定义
Objective-C
- (instancetype)initWithFrame:(CGRect)frame splashId:(NSString *)splashId;
- (void)show;
示例
Objective-C
- (void)viewDidLoad { [super viewDidLoad]; ICDPSplashView *splashView = [[ICDPSplashView alloc]initWithFrame:[UIScreen mainScreen].bounds splashId:@"splashId"]; [splashView show];}- (void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear: animated]; [self.splashView close];}
闪屏示例
接入切屏广告
调用 ICDPManager 中 addMonitorCutscreenWithBoothId 方法,传入广告位 ID 即可在切屏后显示对应的切屏广告,可自定义传入切后台时间间隔。 调用 removeMonitor 则实现暂停切屏。
接口定义
Objective-C
- (void)addMonitorCutscreenWithBoothId:(NSString *)boothId;- (void)addMonitorCutscreenWithBoothId:(NSString *)boothId frontAndBackIntervalTime:(NSTimeInterval)intervalTime;- (void)removeMonitor