CFMobAdverSDK 是一款轻量级的广告 SDK,包括开屏广告、横幅广告、插屏广告
SDK 下载-->SDK 配置代码-->广告测试-->App 发布
本文档面向所有使用该 SDK 的开发人员、测试人员以及对此感兴趣的其他用户。
iOS 8.0
注:以下截图均在示例程序(CFMobAdSDKDemom)中可以找到。
在 info.plist
中,在 NSAppTransportSecurity
下将 NSAllowsArbitraryLoads
设置为 true
。
允许在前台使用时获取 GPS 的描述 NSLocationAlwaysUsageDescription=YES
。
允许永久使用 GPS 的描述 NSLocationWhenInUseUsageDescription=YES
。
将 other linker flags
设置为 -ObjC
。
Build Phases
--->Link Bunary With Libraries
添加库 AdSupport.framework
、CoreLocation.framework
。
修改以下方法中的 AppID
的值为自己的 AppID
,并配置自己的开发环境。
[CFAdvertisement registerAppID:@"0446c3a9b4da4810aebd8c2fc8dd1a74" developModel:CFSDKModeDevelopment];
SDK
、AdSupport.framework
、CoreLocation.framework
。1.初始广告视图
First Header | Second Header |
---|---|
1 | 初始化广告视图实例 |
2 | 设置 frame 和 delegate,广告类型等属性 |
3 | 启动广告(start) |
#import "CFMobAdView.h"
- (void)viewDidLoad {
[super viewDidLoad];
//使 嵌 告的 法实 。
self.bannerView = [[CFMobAdView alloc] init];
self.bannerView.adType = CFMobAdViewTypeBanner;
CGFloat bannerY = kScreenHeight - 0.15*kScreenWidth;
self.bannerView.frame = CGRectMake(0, bannerY, kScreenWidth, 0.15*kScreenWidth);
[self.view addSubview:self.bannerView];
self.bannerView.delegate = self;
[self.bannerView start];
// sharedAdView.delegate = self;
[self.bannerView start];
}
2.可选 delegate 接口
/// 广告展示成功
- (void)bannerSuccessPresentScreen{
}
/// 广告展示失败
- (void)bannerFailPresentScreenWithError:(CFMobFailReason) reason{
}
/// 广告被点击
- (void)bannerDidClicked{
}
/// 广告详情消失
- (void)bannerDidDismissLp{
}
1.展示开屏广告 在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
中
First Header | Second Header |
---|---|
1 | 初始化开屏广告实例 |
2 | 设置 delegate,广告类型等属性。 |
3 | 加载广告(loadAndDisplayUsingKeyWindow) |
开屏属性中 canSplashClick
为开屏是否可以点击属性,默认为可以点击。(投不可点击的广告主较少,建议使用默认设置即可。)
// 全屏 告
CFMobAdSplashView *splashView = [[CFMobAdSplashView alloc] init];
splashView.delegate = self;
splashView.canSplashClick = YES;
[splashView loadAndDisplayUsi
2.可选 delegate
接口 在开屏广告的生命周期内,会通过 delegate
通知回调相关事件:开屏广告加载是否成功、展示是否成功、展示开始、展示结束等信息。如需要,您可以利用这些信息进行处理,建议在开屏广告展示成功结束,或者广告展示失败的回调进行后续处理,详细使用方法请参见 CFMobAdSplashDelegate.h
。
First Header | Second Header |
---|---|
1 | 初始化自定义开屏 customSplashView 并添加到 window |
2 | 初始化开屏广告容器 SplashContainer 并添加到 customSplashView |
3 | 初始化 CFMobAdSplashView |
4 | 设置 delegate 和开屏属性 |
5 | 在 SplashContainer 内加载广告(loadAndDisplayUsingContainerView) |
1.展示开屏广告(在 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
中)开屏属性中 canSplashClick
为开屏是否可以点击属性,默认为可以点击
注意:半屏幕开屏尺寸必须大于
200*200
,并且落在 window 内部
- (BOOL)application:(UIApplication *)application didFinishLaunchingWith
Options:(NSDictionary *)launchOptions {
// 定义开屏
CFMobAdSplashView *splashView = [[CFMobAdSplashView alloc] init];
splashView.delegate = self;
self.splashView = splashView;
[self.window addSubview:splashView];
//可以在customSplashView上显示包含icon的 定义开屏
self.customSplashView = [[UIView alloc] initWithFrame:self.window.frame];
self.customSplashView.backgroundColor = [UIColor whiteColor];
[self.window addSubview:self.customSplashView];
CGFloat screenWidth = self.window.frame.size.width;
CGFloat screenHeight = self.window.frame.size.height;
//在SplashContainer 做上展现 告的容 ,注意尺 必须 于200*200,并且Splas hContainer需要全部在window内,同时开机画 建议旋转
UIView * SplashContainer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight - 40)];
[self.customSplashView addSubview:SplashContainer];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, screenHeight - 40, screenWidth, 20)];
label.text = @"上 为开屏 告位";
label.textAlignment = NSTextAlignmentCenter;
[self.customSplashView addSubview:label];
//在的SplashContainer 展现 告
[splashView loadAndDisplayUsingContainerView:SplashContainer];
return YES;
}
2. 可选 delegate
接口 在开屏广告的生命周期内,会通过 delegate
通知回调相关事件:开屏广告加载是否成功、展示是否成功、展示开始、展示结束等信息。如需要,您可以利用这些信息进行处理,建议在开屏广告展示成功结束,或者广告展示失败的回调进行后续处理。对于半屏开屏,建议在广告展示失败和结束时移除自定义的 customSplashView
/**
* 广告告展示失败
*/
- (void)splashlFailPresentScreenWithError:(CFMobFailReason) reason{
NSLog(@"%s",__func__);
[self.customSplashView removeFromSuperview];
}
/**
* 广告被点击
*/
- (void)splashDidClicked{
NSLog(@"%s",__func__);
[self.customSplashView removeFromSuperview];
}
/**
* 广告展示结束
*/
- (void)splashDidDismissScreen{
NSLog(@"%s",__func__);
[self.customSplashView removeFromSuperview];
}
1. 预加载插屏广告
序号 | 详细信息 |
---|---|
1 | 初始化插屏广告实例 |
2 | 设置 delegate, 广告类型等属性 |
3 | 预加载广告 (load) |
4 | 展示广告 (show) |
- (IBAction)clickLoadAd:(id)sender {
self.interstitialView = [[CFMobAdInterstitialView alloc] init];
self.interstitialView.delegate = self;
//插屏类型
self.interstitialView.interstitialType = CFMobAdViewTypeInterstitialOther;
//插屏显示类型
self.interstitialView.interstitialShowType = CFMobAdInterstitialShowType_Full;
//加载全屏插屏
[self.interstitialView load];
}
插屏广告有以下几种应用场景
CFMobAdViewTypeInterstitialOther
CFMobAdViewTypeInterstitialBeforeVideo
CFMobAdViewTypeInterstitialPauseVideo
目前只使用第一种普通场景,也可以不设置
插屏广告显示类型
CFMobAdInterstitialShowType_Full
CFMobAdInterstitialShowType_Custom
CFMobAdInterstitialShowType_Full _Custom
2. 展示插屏广告
// 注意:这里要先确定isReady之后在调presentFromRootViewController: 法,否则 可能 会显示,可以根据interstitialSuccessToLoadAd 法确定
if (self.interstitialView.isReady) {
if (_curType == 1) {
[self.interstitialView presentFromRootViewController:self];
}
}
3. 可选 delegate
接口 在插屏广告的生命周期内,通过 delegate
通知回调相关事件:插屏广告加载是否成功,展示是否成功,展示开始和展示结束等。具体方法请参见 CFMobAdInterstitiaDelegate.h