1 Star 0 Fork 0

华资融创 / CXHAdSDK

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
Loading...
README
MIT

[toc]

修订历史

文档版本 修订日期 修订说明
V1.0.0 2022-03-30 SDK初始版本
v1.0.1 2022-04-19 新增支持广点通信息流模板广告
V1.0.2 2022-04-25 新增支持channel渠道广告,新增广告容器组件
V1.0.3 2022-04-28 新增插屏广告场景参数的设置
V1.0.4 2022-05-13 新增信息流自渲染广告、新增信息流模板插屏样式组件
V1.0.5 2022-05-30 新增非标准广告接入代码示例
V1.0.6 2022-06-15 新增落地页scheme跳转处理
V1.0.7 2022-06-22 新增初始化和channel域名配置功能
V1.0.8 2022-07-08 新增渠道RC、修复已知bug
V1.0.9 2022-07-26 修复ua异常
V1.0.11 2022-08-04 插屏广告新增展示时长功能,修复已知bug
V1.0.13 2022-08-22 插屏广告新增倒计时按钮
V1.0.14 2022-09-05 请求超时时长修改
V1.0.15 2022-10-07 新增开屏广告,修复已知bug
V1.0.16 2022-10-11 去除非标广告的广告标识
V1.0.17 2022-10-21 新增支持服务端配置各渠道域名,修复已知bug
V1.0.18 2022-10-25 适配swift,修复已知bug
V1.0.19 2022-11-09 修复已知bug
V1.0.20 2022-12-05 修复iOS11适配问题,修复已知bug
V1.0.21 2023-01-04 新增服务广告调用类型(原非标广告类型)
V1.0.22 2023-01-11 修复部分渠道域名未生效问题
V1.0.23 2023-01-19 修复请求头参数问题,修改文档中部分拓词
V1.0.24 2023-03-01 增加广告竞价逻辑
V1.0.25 2023-03-09 增加停止广告请求逻辑
V1.0.26 2023-03-15 修复已知bug
V1.0.27 2023-03-19 添加开屏热区,新增开屏跳过按钮位置调整
V1.0.28 2023-03-28 广告logo调整,修复已知bug
V1.0.29 2023-04-10 适配CAID
V1.0.30 2023-04-17 自定义关闭按钮的展示
V1.1.0 2023-04-19 修复已知bug
V1.1.1 2023-04-21 增加caid相关接口
V1.1.2 2023-05-08 修复已知bug
V1.2.0 2023-05-08 新增CAID相关参数
V1.2.1 2023-06-26 异步初始化适配
V1.2.2 2023-07-16 广告上报优化
V1.2.3 2023-07-24 广告展示上报优化,时间宏替换优化,修复已知bug
V1.3.0 2023-08-09 开屏支持广点通,开屏逻辑优化,修复已知bug

1.1 概述

尊敬的开发者朋友,欢迎您使用程序化聚合SDK。通过本文档,您可以在几分钟之内轻松完成广告的集成过程。

操作系统: iOS 9.0 及以上版本

运行设备:iPhone (iPad上可能部分广告正常展示,但是存在填充很低或者平台不支持等问题,建议不要在iPad上展示广告)


2.1 自动部署

自动部署可以省去您工程配置的时间。iOS SDK会通过CocoaPods进行发布,推荐您使用自动部署。

// 使用https://gitee.com/huazi-rongchuang/cxhadsdk-ios-repo.git源可以快速导入SDK
// 挑选其中需要导入的平台
pod 'CXHAdSDK/GDT'
pod 'CXHAdSDK/BWT'
pod 'CXHAdSDK/Channel'
pod 'CXHAdSDK/RC'
// 根据情况酌情考虑是否导入,其中ChannelRC是必须的

常用SDK最新的版本号

// 基础库
CXHAdSDK-Adapter (1.2.3)
CXHAdSDK-Kit (1.3.0)
// 各平台,其中包含GDTChannelBWTRC版本号都为1.3.0
CXHAdSDK (1.3.0)  

2.2 手动部署

手动部署是下载静态库,然后手动导入到您的项目中去。

点击进入SDK下载地址

下载各模块拖入到工程中,在Demo中的Pods/Development Pods/CXHAdSDK目录下也可以找到所有的模块。

  • 广告调用所需framework(必需)

广告适配器:Adapter广告SDK适配器模块

主控制器:Core广告SDK主控制器模块

基础库:Base广告SDK基础类模块

  • 广点通平台

优量汇适配器:广告SDK-GDT适配器模块

优量汇SDK:GDT广告SDK

  • channel平台(必需)

channel适配器:广告SDK-channel适配器模块

  • RC平台(必需)

RC适配器:广告SDK-RC适配器模块

手动方式导入,需要添加如下依赖库:

AdSupport.framework
CoreLocation.framework
QuartzCore.framework
SystemConfiguration.framework
CoreTelephony.framework
Security.framework
StoreKit.framework
AVFoundation.framework
WebKit.framework
libz.tbd
libxml2.tbd
## 3.1 工程环境配置

打开项目的 app target,查看 Build Settings 中的 Linking-Other Linker Flags 选项,确保含有 -ObjC 一值, 若没有则添加。

  1. 在项目的 app target 中,查看 Build Settings 中的 Build options - Enable Bitcode 选项, 设置为NO。
  2. info.plist 添加支持 Http访问字段
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
  1. Info.plist 添加定位权限字段
NSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDeion
  1. Info.plist设置白名单
<key>LSApplicationQueriesSchemes</key>
    <array>
        <string>dianping</string>
        <string>imeituan</string>
        <string>com.suning.SuningEBuy</string>
        <string>suning</string>
        <string>openapp.jdmobile</string>
        <string>vipshop</string>
        <string>snssdk141</string>
        <string>ctrip</string>
        <string>qunariphone</string>
        <string>QunarAlipay</string>
        <string>qunaraphone</string>
        <string>yohobuy</string>
        <string>kaola</string>
        <string>qqnews</string>
        <string>openapp.xzdz</string>
        <string>beibeiapp</string>
        <string>taobao</string>
        <string>tmall</string>
        <string>openjd</string>
        <string>jd</string>
        <string>jhs</string>
        <string>weixin</string>
        <string>yhd</string>
        <string>wireless1688</string>
        <string>GomeEShop</string>
        <string>wbmain</string>
        <string>xhsdiscover</string>
        <string>douyin</string>
        <string>pinduoduo</string>
        <string>jdmobile</string>
        <string>tbopen</string>
        <string>pddopen</string>
        <string>mogujie</string>
        <string>koubei</string>
        <string>eleme</string>
        <string>youku</string>
        <string>gengmei</string>
        <string>airbnb</string>
        <string>alipays</string>
        <string>alipay</string>
        <string>didicommon</string>
        <string>OneTravel</string>
        <string>farfetchCN</string>
        <string>farfetch</string>
        <string>snssdk1112</string>
        <string>snssdk1128</string>
        <string>miguvideo</string>
        <string>kfcapplinkurl</string>
        <string>iqiyi</string>
        <string>uclink</string>
        <string>app.soyoung</string>
        <string>qqmusic</string>
        <string>kwai</string>
        <string>ksnebula</string>
        <string>taobaolite</string>
        <string>lianjiabeike</string>
     </array>

3.2 iOS14适配

由于iOS14中对于权限和隐私内容有一定程度的修改,而且和广告业务关系较大,请按照如下步骤适配,如果未适配。不会导致运行异常或者崩溃等情况,但是会一定程度上影响广告收入。敬请知悉。

  1. 应用编译环境升级至 Xcode 12.0 及以上版本;
  2. 设置IDFA权限;

3.2.1 IDFA

从 iOS 14 开始,在应用程序调用 App Tracking Transparency 向用户提跟踪授权请求之前,IDFA 将不可用。

  1. 更新 Info.plist,添加 NSUserTrackingUsageDescription 字段和自定义文案描述。
<key>NSUserTrackingUsageDescription</key>
<string>该标识符将用于向您投放个性化广告</string>
  1. 向用户申请权限。
#import <AppTrackingTransparency/AppTrackingTransparency.h>
#import <AdSupport/AdSupport.h>
...
- (void)requestIDFA {
  if (@available(iOS 14, *)) {
        [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(ATTrackingManagerAuthorizationStatus status) {
            if (status == ATTrackingManagerAuthorizationStatusAuthorized) {
                // 请求广告
                [self requestAd]
            }
        }];
  }
}

4.1 CXHAdSDK的初始化

申请的appid和你的包名相对应,根据双方协调,去确定需要拉取的广告平台

[CXHAdSDK initWithAppId:@"appid" completionBlock:^(NSError * _Nullable error) {
    if (error) {
         NSLog(@"初始化失败:%@", error);
    }
}];

用户日志输出等级

[CXHAdSDK setLogLevel:CXHSDKLogLevelError];

设置渠道信息

CXHChannelInfo *channelInfo = [[CXHChannelInfo alloc]init];
// bwt上报需要设置
channelInfo.userID = @"123";
[CXHAdSDK setChannelInfo:channelInfo];

设置停止广告请求

[CXHAdSDK setNoAd];

设置请求域名

[CXHAdSDK setRequestDomain:@"http://ad.shunchangzhixing.com"];
## 4.2 banner广告 - CXHAdSDKBannerAdView

横幅广告推荐放置在页面固定位置

横幅广告 - CXHAdSDKBannerAdView:

@interface CXHAdSDKBannerAdView : UIView

/**
 广告生命周期代理
*/
@property (nonatomic, weak) id<CXHSDKBannerAdViewDelegate> delegate;

/**
 广告位id
*/
@property (nonatomic, copy) NSString *posId;

/**
 banner刷新时间间隔,30-120s之间.
*/
@property (nonatomic, assign) int refershTime;

/**
 是否展示关闭按钮,默认不展示,为YES则展示
*/
@property (nonatomic, assign) BOOL showCloseView;

/**
 请求超时时间,默认为4s,需要设置3s及以上,暂不生效
*/
@property (nonatomic, assign) NSInteger tolerateTimeout;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
*/
@property (nonatomic, weak) UIViewController *controller;

- (id)new NS_UNAVAILABLE;
- (id)init NS_UNAVAILABLE;

/*
 初始化bannerView
 @param frame 期望的banner视图尺寸
*/
- (instancetype)initWithFrame:(CGRect)frame;

/**
 拉取并展示广告
*/
- (void)loadAndShow;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

横幅广告 - CXHSDKBannerAdViewDelegate

@protocol CXHSDKBannerAdViewDelegate <NSObject>

/**
 广告获取成功
 
 @param bannerView banner实例
 */
- (void)CXH_bannerViewDidReceived:(CXHAdSDKBannerAdView *)bannerView;

/**
 广告拉取失败
 
 @param bannerView banner实例
 @param error 错误描述
 */
- (void)CXH_bannerViewFailToReceived:(CXHAdSDKBannerAdView *)bannerView error:(NSError *)error;

/**
 广告点击
 
 @param bannerView 广告实例
 @param loadingPageURL 广告落地页地址,当渠道为bwt,并且customLoadingPage为YES时有值
 */
- (void)CXH_bannerViewClicked:(CXHAdSDKBannerAdView *)bannerView loadingPageURL:(NSString *)loadingPageURL;

/**
 广告关闭
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerViewClose:(CXHAdSDKBannerAdView *)bannerView;

/**
 广告展示
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerViewExposure:(CXHAdSDKBannerAdView *)bannerView;

/**
 关闭落地页
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerAdCloseLandingPage:(CXHAdSDKBannerAdView *)bannerView;

@end

横幅广告请求示例:

#import "CXHAdSDKBannerAdView.h"

// 1 初始化banner视图

_bannerView = [[CXHAdSDKBannerAdView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
_bannerView.delegate = self;
_bannerView.controller = self;
_bannerView.refershTime = 35;
_bannerView.posId = @"MSX_BN_00003";
_bannerView.customLoadingPage = YES;
// _bannerView.showCloseView = YES;
_bannerView.backgroundColor = [UIColor redColor];
// 查看价格,需要在设置广告位id之后调用
NSLog(@"price----%ld", [_bannerView getBidPrice]);
// 发送竞价失败上报,此时的价格为第三方赢价的价格
// [_bannerView sendLossNotice:100];
// 发送竞价成功上报
[_bannerView sendWinNotice:100];
    
// 2 添加到父视图上
_bannerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height  - height - 100, width, height);
[self.view addSubview:_bannerView];
    
// 3 加载并显示广告 注意: 请确保banner视图显示在屏幕内的时候,调用load方法
[_bannerView loadAndShow];

// 4 代理回调
#pragma mark - CXHSDKBannerAdViewDelegate
/**
 广告获取成功
 
 @param bannerView banner实例
 */
- (void)CXH_bannerViewDidReceived:(CXHAdSDKBannerAdView *)bannerView{
    
}

/**
 广告拉取失败
 
 @param bannerView banner实例
 @param error 错误描述
 */
- (void)CXH_bannerViewFailToReceived:(CXHAdSDKBannerAdView *)bannerView error:(NSError *)error{
  dispatch_async(dispatch_get_main_queue(), ^{
        [_bannerView removeFromSuperview];
    		_bannerView = nil;
    });
}

/**
 广告点击
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerViewClicked:(CXHAdSDKBannerAdView *)bannerView loadingPageURL:(nonnull NSString *)loadingPageURL{
    
}

/**
 广告关闭
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerViewClose:(CXHAdSDKBannerAdView *)bannerView{
    dispatch_async(dispatch_get_main_queue(), ^{
        _bannerView = nil;
    });
}

/**
 广告展示
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerViewExposure:(CXHAdSDKBannerAdView *)bannerView{
    
}

/**
 关闭落地页
 
 @param bannerView 广告实例
 */
- (void)CXH_bannerAdCloseLandingPage:(CXHAdSDKBannerAdView *)bannerView{
    
}

4.3 插屏广告 - CXHAdSDKInterstitialAd

插屏广告是移动广告的一种常见形式,在应用开流程中弹出,当应用展示插页式广告时,用户可以选择点按广告,访问其目标网址,也可以将其关闭,返回应用。

插屏广告 - CXHAdSDKInterstitialAd:

@interface CXHAdSDKInterstitialAd : NSObject

/**
 代理回调
*/
@property (nonatomic, weak) id<CXHAdSDKInterstitialAdDelegate> delegate;

/*
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
 */
@property (nonatomic, weak) UIViewController *controller;

/**
 请求超时时间,默认为4s,需要设置3s及以上
 */
@property (nonatomic, assign) NSInteger tolerateTimeout;

/**
 广告位id
*/
@property (nonatomic, copy) NSString *posId;

/**
 广告尺寸,需与平台所申请广告位比例一致,否则会导致素材压缩
 */
@property (nonatomic, assign) CGSize adSize;

/**
 是否静音,默认静音
 */
@property (nonatomic, assign) BOOL isMuted;

/**
 插屏展示时间,对渠道广点通无效,默认为0(为0则需要用户手动关闭)
 */
@property (nonatomic, assign) NSInteger showTime;

/**
 *  广告是否有效,以下情况会返回NO,建议在展示广告之前判断,否则会影响计费或展示失败
 *  a.广告未拉取成功
 *  b.广告已经曝光过
 *  c.广告过期
 *
 */
@property (nonatomic, readonly) BOOL isAdValid;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 加载广告数据
*/
- (void)loadAdData;

/**
 展示广告
*/
- (void)show;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

插屏广告代理回调 - CXHAdSDKInterstitialAdDelegate

@protocol CXHAdSDKInterstitialAdDelegate <NSObject>

/**
 CXHAdSDKIntertitialAd请求成功回调
 
 @param interstitialAd 插屏广告实例对象
*/
- (void)CXH_interstitialAdSuccedToLoad:(CXHAdSDKInterstitialAd *)interstitialAd;

/**
 CXHAdSDKIntertitialAd请求失败回调

 @param interstitialAd 插屏广告实例对象
 @param error 失败原因
*/
- (void)CXH_interstitialAdFailedToLoad:(CXHAdSDKInterstitialAd *)interstitialAd error:(NSError *)error;

/**
 CXHAdSDKIntertitialAd展示在屏幕内回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)CXH_interstitialAdDidPresent:(CXHAdSDKInterstitialAd *)interstitialAd;

/**
 CXHAdSDKIntertitialAd展示在屏幕内失败回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)CXH_interstitialAdFailedToPresent:(CXHAdSDKInterstitialAd *)interstitialAd error:(NSError *)error;

/**
 CXHAdSDKIntertitialAd点击回调

 @param interstitialAd 插屏广告实例对象
 @param loadingPageURL 广告落地页地址,当渠道为bwt,并且customLoadingPage为YES时有值
*/
- (void)CXH_interstitialAdDidClick:(CXHAdSDKInterstitialAd *)interstitialAd loadingPageURL:(NSString *)loadingPageURL;

/**
 CXHAdSDKIntertitialAd关闭回调

 @param interstitialAd 插屏广告实例对象
*/
- (void)CXH_interstitialAdDidClose:(CXHAdSDKInterstitialAd *)interstitialAd;

/**
 CXHAdSDKIntertitialAd展示回调
 
 @param interstitialAd 广告实例
 */
- (void)CXH_interstitialAdExposure:(CXHAdSDKInterstitialAd *)interstitialAd;

/**
 CXHAdSDKIntertitialAd关闭落地页回调
 
 @param interstitialAd 广告实例
 */
- (void)CXH_interstitialAdCloseLandingPage:(CXHAdSDKInterstitialAd *)interstitialAd;

@end

插屏广告 - CXHAdSDKInterstitialAd请求示例:

#import "CXHAdSDKInterstitialAd.h"

// 1、插屏广告广告初始化
_interstitialAd = [[CXHAdSDKInterstitialAd alloc]init];
_interstitialAd.delegate = self;
_interstitialAd.controller = self;
_interstitialAd.posId = @"MSX_BN_00003";
_interstitialAd.customLoadingPage = YES;
// 设置插屏广告的展示时长为5s,5s后自动消失
_interstitialAd.showTime = 5;
    // 场景id
    [_interstitialAd setInterstitialScenes:@{
        @"station_id":@"123",
        @"in_out":@"0",
        @"userid":@"123",
    }];
// 查看价格,需要在设置广告位id之后调用
NSLog(@"price----%ld", [_interstitialAd getBidPrice]);
// 发送竞价失败上报,此时的价格为第三方赢价的价格
// [_interstitialAd sendLossNotice:100];
// 发送竞价成功上报
[_interstitialAd sendWinNotice:100];  
// 2、加载插屏广告
[_interstitialAd loadAdData];

//3、推荐在请求成功回调之后展示插屏广告
/**
 CXHAdSDKIntertitialAd请求成功回调
 
 @param interstitialAd 插屏广告实例对象
*/
- (void)CXH_interstitialAdSuccedToLoad:(CXHAdSDKInterstitialAd *)interstitialAd{
//    // 推荐在该回调之后展示插屏广告
//    dispatch_async(dispatch_get_main_queue(), ^{
//        [self showAd];
//    });
}

/**
 CXHAdSDKIntertitialAd请求失败回调

 @param interstitialAd 插屏广告实例对象
 @param error 失败原因
*/
- (void)CXH_interstitialAdFailedToLoad:(CXHAdSDKInterstitialAd *)interstitialAd error:(NSError *)error{
    _interstitialAd = nil;
}

##4.4 信息流模板广告 - CXHAdSDKNativeExpressAd

信息流模板广告是一种自动化展现的原生广告,返回的是广告视图,可以支持多个样式(广告视图生命周期和模板广告实例对象绑定,暂时只支持广点通):

信息流模板广告 - CXHAdSDKNativeExpressAd:

@interface CXHAdSDKNativeExpressAd : NSObject

- (instancetype)new NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;

- (instancetype)initWithAdSize:(CGSize)adSize;

/**
 代理回调
*/
@property (nonatomic, weak) id<CXHAdSDKNativeExpressAdDelegate> delegate;

/*
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
 */
@property (nonatomic, weak) UIViewController *controller;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 广告位id
*/
@property (nonatomic, copy) NSString *posId;

/**
 是否静音,默认静音
 */
@property (nonatomic, assign) BOOL isMuted;

/**
 信息流自动播放,默认WiFi自动播放 开启后WiFi/4G自动播放
 */
@property(nonatomic ,assign) BOOL autoPlay;

/**
 加载广告

 @param count 拉取几条广告,建议区间 1~5, 超过可能无法拉取到
 */
- (void)load:(int)count;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

信息流模板广告代理回调 - CXHAdSDKNativeExpressAdDelegate

@protocol CXHAdSDKNativeExpressAdDelegate <NSObject>

@optional

/**
 信息流广告请求成功

 @param nativeAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)CXH_nativeAdSucessToLoad:(CXHAdSDKNativeExpressAd *)nativeAd
                      adViewArray:(NSArray<__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *> *)adViewArray;

/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)CXH_nativeAdFailToLoad:(CXHAdSDKNativeExpressAd *)nativeAd
                     error:(NSError *)error;

/**
 信息流广告渲染成功

 @param adView 广告视图
 */
- (void)CXH_nativeAdViewRenderOrRegistSuccess:(UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView;

/**
 信息流广告渲染失败

 @param adView 广告视图
 */
- (void)CXH_nativeAdViewRenderOrRegistFail:(UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView;

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClicked:(CXHAdSDKNativeExpressAd *)nativeAd
                      adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL;

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClose:(CXHAdSDKNativeExpressAd *)nativeAd
                    adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView;

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposure:(CXHAdSDKNativeExpressAd *)nativeAd
                       adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView;

/**
 信息流广告落地页被关闭
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdCloseLandingPage:(CXHAdSDKNativeExpressAd *)nativeAd
                       adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView;

@end

信息流模板广告请求示例:

#import "CXHAdSDKNativeExpressAd.h"

// load ad
- (void)onRefreshClicked:(id)sender{
    if (!_nativeExpressAd) {
        CXHAdSDKNativeExpressAd *expressAd = [[CXHAdSDKNativeExpressAd alloc]initWithAdSize:CGSizeMake([UIScreen mainScreen].bounds.size.width, 10)];
        expressAd.delegate = self;
        expressAd.controller = self;
        expressAd.posId = @"MSX_BN_00001";
        _nativeExpressAd = expressAd;
        // 查看价格,需要在设置广告位id之后调用,需要在设置广告位id之后调用
				NSLog(@"price----%ld", [_nativeExpressAd getBidPrice]);
				// 发送竞价失败上报,此时的价格为第三方赢价的价格
				// [_nativeExpressAd sendLossNotice:100];
				// 发送竞价成功上报
				[_nativeExpressAd sendWinNotice:100];  
    }
    [_nativeExpressAd load:2];
}

// 代理回调
#pragma mark - CXHAdSDKNativeExpressAdDelegate

/**
 信息流广告请求成功

 @param nativeAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)CXH_nativeAdSucessToLoad:(CXHAdSDKNativeExpressAd *)nativeAd
                     adViewArray:(NSArray<__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *> *)adViewArray{
//    [self.adItems addObjectsFromArray:adViewArray];
    for (UIView<CXHAdapterNativeExpressAdViewDelegate> *adView in adViewArray) {
        // 必需调用
        [adView render];
    }
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)CXH_nativeAdFailToLoad:(CXHAdSDKNativeExpressAd *)nativeAd
                         error:(NSError *)error{
    [self.tableView.mj_header endRefreshing];
    [self.tableView.mj_footer endRefreshing];
}

/**
 信息流广告渲染成功

 @param adView 广告视图
 */
- (void)CXH_nativeAdViewRenderOrRegistSuccess:(UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    // 注册或渲染成功,此时高度正常,可以展示
    dispatch_async(dispatch_get_main_queue(), ^{
        for (int i = 0; i < 6; i ++) {
            [self.items addObject:[NSNull null]];
        }
        [self.items addObject:adView];
        [self.tableView reloadData];
    });
}

/**
 信息流广告渲染失败

 @param adView 广告视图
 */
- (void)CXH_nativeAdViewRenderOrRegistFail:(UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    
}

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClicked:(CXHAdSDKNativeExpressAd *)nativeAd
                     adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL{
    
}

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClose:(CXHAdSDKNativeExpressAd *)nativeAd
                   adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    // 广告被关闭,移除广告
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.items removeObject:adView];
        [self.tableView reloadData];
    });
}

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposure:(CXHAdSDKNativeExpressAd *)nativeAd
                      adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    
}

/**
 信息流广告落地页被关闭
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdCloseLandingPage:(CXHAdSDKNativeExpressAd *)nativeAd
                              adView:(__kindof UIView<CXHAdapterNativeExpressAdViewDelegate> *)adView{
    
}

信息流模版广告注意事项:

  • 信息流拉取成功后, 获得的 CXHAdSDKNativeExpressAd 广告视图需要调用 [adview render] 方法, 否则无法进行广告的点击上报和展现上报。在渲染成功的回调中再调用render方法,会再次调起渲染成功回调,造成死循环
  • 必需在广告加载完成之后再进行下一次load。

4.5 广告容器组件 - CXHBWTAdContainerView

广告容器组件是一种特殊需求的广告容器视图,它提供了一种对CXHAdSDK的封装方式。在CXHBWTAdContainerView中支持请求信息流模板广告和banner广告,支持左右滑动关闭设置,支持展示时长设置。需要单独导入文件CXHBWTAdContainerView

广告容器组件 - CXHBWTAdContainerView:

@interface CXHBWTAdContainerView : UIView
// 是否支持左滑关闭
@property (nonatomic, assign) BOOL swipeLeft;
// 是否支持右滑关闭
@property (nonatomic, assign) BOOL swipeRight;
// 广告展示时间,单位:秒,为0,则不限制展示时间,默认为0
@property (nonatomic, assign) NSInteger showTime;
// 请求广告类型,目前支持banner和信息流模板广告
@property (nonatomic, assign) CXHAdapterAdType adType;
/**
 广告生命周期代理
*/
@property (nonatomic, weak) id<CXHBWTAdContainerViewDelegate> delegate;
/**
 banner刷新时间间隔,30-120s之间,adType为banner必填
*/
@property (nonatomic, assign) int refershTime;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 是否静音,默认静音,信息流模版广告需要
 */
@property (nonatomic, assign) BOOL isMuted;

/**
 信息流自动播放,默认WiFi自动播放 开启后WiFi/4G自动播放,信息流模版广告需要
 */
@property(nonatomic ,assign) BOOL autoPlay;

/**
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
*/
@property (nonatomic, weak) UIViewController *controller;

- (id)new NS_UNAVAILABLE;
- (id)init NS_UNAVAILABLE;

/*
 初始化bannerView
 @param frame 期望的banner视图尺寸
*/
- (instancetype)initWithFrame:(CGRect)frame;

- (void)requestAdViewWithPosId:(NSString *)posid;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

广告容器组件代理回调 - CXHBWTAdContainerViewDelegate

@class CXHBWTAdContainerView;

@protocol CXHBWTAdContainerViewDelegate <NSObject>

- (void)adContainerViewDidReceived:(CXHBWTAdContainerView *)adContainerView;

- (void)adContainerViewFailToReceived:(CXHBWTAdContainerView *)adContainerView error:(NSError *)error;

- (void)adContainerViewClicked:(CXHBWTAdContainerView *)adContainerView loadingPageURL:(NSString *)loadingPageURL;

- (void)adContainerViewExposure:(CXHBWTAdContainerView *)adContainerView;

- (void)adContainerViewClose:(CXHBWTAdContainerView *)adContainerView;

- (void)adContainerViewCloseLandingPage:(CXHBWTAdContainerView *)adContainerView;

@end

广告容器组件请求示例:

- (void)loadBanner {
    CGFloat height = [UIScreen mainScreen].bounds.size.width * 110/335;
    CGFloat width = [UIScreen mainScreen].bounds.size.width;
    _adContainerView = [[CXHBWTAdContainerView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
    _adContainerView.delegate = self;
    _adContainerView.controller = self;
    _adContainerView.refershTime = 35;
    _adContainerView.adType = CXHSDKAdapterAdTypeBanner;
    _adContainerView.swipeLeft = YES;
    _adContainerView.swipeRight = YES;
//    _adContainerView.showTime = 5;
    _adContainerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height  - height - 100 - 100, width, height);
    // 当adType = CXHAdapterAdTypeBanner,需要在请求前添加到可视视图中(广点通要求)
    [self.view addSubview:_adContainerView];
    [_adContainerView requestAdViewWithPosId:@"MSX_BN_00001"];
    // 查看价格,需要在设置广告位id之后调用
		NSLog(@"price----%ld", [_adContainerView getBidPrice]);
		// 发送竞价失败上报,此时的价格为第三方赢价的价格
		// [_adContainerView sendLossNotice:100];
		// 发送竞价成功上报
		[_adContainerView sendWinNotice:100];  
}

- (void)loadNativeExpress {
    _adContainerView = [[CXHBWTAdContainerView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, 10)];
    _adContainerView.delegate = self;
    _adContainerView.controller = self;
    _adContainerView.swipeLeft = YES;
    _adContainerView.swipeRight = YES;
//    _adContainerView.showTime = 10;
    _adContainerView.adType = CXHSDKAdapterAdTypeNativeExpress;
    // adType = CXHAdapterAdTypeNativeExpress, 只有在成功回调中视图才渲染完成,此时才有正确高度,建议此时添加到父视图上去
//    [self.view addSubview:_adContainerView];
    [_adContainerView requestAdViewWithPosId:@"MSX_BN_00001"];
    // 查看价格,需要在设置广告位id之后调用
		NSLog(@"price----%ld", [_adContainerView getBidPrice]);
		// 发送竞价失败上报,此时的价格为第三方赢价的价格
		// [_adContainerView sendLossNotice:100];
		// 发送竞价成功上报
		[_adContainerView sendWinNotice:100];  
}


#pragma mark - CXHBWTAdContainerViewDelegate
- (void)adContainerViewDidReceived:(CXHBWTAdContainerView *)adContainerView{
      // adType = CXHAdapterAdTypeNativeExpress, 只有在成功回调中视图才渲染完成,此时才有正确高度,建议此时添加到父视图上去
    if (adContainerView.adType == CXHSDKAdapterAdTypeNativeExpress) {
        [self.view addSubview:_adContainerView];
        CGSize size = _adContainerView.frame.size;
        _adContainerView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height - size.height - 50 - 100, size.width, size.height);
    }
}

- (void)adContainerViewFailToReceived:(CXHBWTAdContainerView *)adContainerView error:(NSError *)error{
    
}

- (void)adContainerViewClicked:(CXHBWTAdContainerView *)adContainerView loadingPageURL:(NSString *)loadingPageURL{
    
}

- (void)adContainerViewExposure:(CXHBWTAdContainerView *)adContainerView{
}

- (void)adContainerViewClose:(CXHBWTAdContainerView *)adContainerView{
    _adContainerView = nil;
}

- (void)adContainerViewCloseLandingPage:(CXHBWTAdContainerView *)adContainerView{
    
}

4.6 信息流自渲染广告 - CXHAdSDKNativeAd

信息流自渲染广告是一种用用户自主渲染样式的原生信息流广告,返回的是广告视图和广告数据,用户可以在广告视图中根据广告数据自行渲染样式:

信息流自渲染广告 - CXHAdSDKNativeAd:

@interface CXHAdSDKNativeAd : NSObject

/**
 代理回调
*/
@property (nonatomic, weak) id<CXHAdSDKNativeAdDelegate> delegate;

/*
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
 */
@property (nonatomic, weak) UIViewController *controller;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 广告位id
*/
@property (nonatomic, copy) NSString *posId;

/**
 是否静音,默认静音
 */
@property (nonatomic, assign) BOOL isMuted;

/**
 信息流自动播放,默认WiFi自动播放 开启后WiFi/4G自动播放
 */
@property(nonatomic ,assign) BOOL autoPlay;

/**
 加载广告

 @param count 拉取几条广告,建议区间 1~5, 超过可能无法拉取到
 */
- (void)load:(int)count;

/**
 是否正在加载广告
 */
- (BOOL)isLoadingAd;

- (void)setAdScenes:(NSDictionary *)scenes;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

信息流自渲染广告代理回调 - CXHAdSDKNativeAdDelegate

@protocol CXHAdSDKNativeAdDelegate <NSObject>

@optional

/**
 信息流原生广告请求成功

 @param nativeAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)CXH_nativeAdSucessToLoad:(CXHAdSDKNativeAd *)nativeAd
                      adViewArray:(NSArray<__kindof UIView<CXHAdapterNativeAdViewDelegate> *> *)adViewArray;

/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)CXH_nativeAdFailToLoad:(CXHAdSDKNativeAd *)nativeAd
                     error:(NSError *)error;

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClicked:(CXHAdSDKNativeAd *)nativeAd
                      adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL;

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClose:(CXHAdSDKNativeAd *)nativeAd
                    adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView;

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposure:(CXHAdSDKNativeAd *)nativeAd
                       adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView;

/**
 信息流广告落地页被关闭
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdCloseLandingPage:(CXHAdSDKNativeAd *)nativeAd
                       adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView;

@end

信息流自渲染广告请求示例:

- (void)loadNativeAd{
    CXHAdSDKNativeAd *nativeAd  = [[CXHAdSDKNativeAd alloc]init];
    _nativeAd = nativeAd;
    _nativeAd.delegate = self;
    _nativeAd.controller = self;
//    _nativeAd.posId = @"22047521";
    _nativeAd.posId = @"MSX_BN_00003";
  
    // 查看价格,需要在设置广告位id之后调用
		NSLog(@"price----%ld", [_nativeAd getBidPrice]);
		// 发送竞价失败上报,此时的价格为第三方赢价的价格
		// [_nativeAd sendLossNotice:100];
		// 发送竞价成功上报
		[_nativeAd sendWinNotice:100]; 
  
    [_nativeAd load:1];
    
}

#pragma mark - CXHAdSDKNativeAdDelegate
/**
 信息流原生广告请求成功

 @param nativeAd 广告实例
 @param adViewArray 广告模板集合
 */
- (void)CXH_nativeAdSucessToLoad:(CXHAdSDKNativeAd *)nativeAd
                     adViewArray:(NSArray<__kindof UIView<CXHAdapterNativeAdViewDelegate> *> *)adViewArray{
    UIView<CXHAdapterNativeAdViewDelegate> *adview = [adViewArray firstObject];
    [adview cxh_registViews:@[adview]];
    CGFloat width = [UIScreen mainScreen].bounds.size.width - 16 * 2;
    CGFloat height = width * 9 / 16;
    adview.frame = CGRectMake(16, ([UIScreen mainScreen].bounds.size.height - height)/2, width, height);
    [self.view addSubview:adview];
    UIImageView *imageView = [[UIImageView alloc]init];
    imageView.frame = CGRectMake(0, 0, width, height);
    [adview addSubview:imageView];
    CXHAdapterNativeAdData *adData = [adview cxh_nativeAdData];
    [imageView sd_setImageWithURL:[NSURL URLWithString:adData.imageUrl]];
    
    UILabel *adLabel = [[UILabel alloc]init];
    adLabel.text = @"广告";
    adLabel.frame = CGRectMake(adview.frame.size.width - 25, adview.frame.size.height - 15, 25, 15);
    adLabel.textAlignment = NSTextAlignmentCenter;
    adLabel.font = [UIFont systemFontOfSize:10];
    [adview addSubview:adLabel];
    adLabel.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0  blue:153/255.0 alpha:1];
    adLabel.backgroundColor = [UIColor colorWithHexString:@"#666666"];
}

/**
 信息流广告请求失败

 @param nativeAd 广告实例
 @param error 请求错误描述
 */
- (void)CXH_nativeAdFailToLoad:(CXHAdSDKNativeAd *)nativeAd
                         error:(NSError *)error{
    
}

/**
 信息流广告被点击

 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClicked:(CXHAdSDKNativeAd *)nativeAd
                     adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView loadingPageURL:(NSString *)loadingPageURL{
    
}

/**
 信息流广告被关闭
 
 @param nativeAd 广告模板
 */
- (void)CXH_nativeAdClose:(CXHAdSDKNativeAd *)nativeAd
                   adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    
}

/**
 信息流广告被展示
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdExposure:(CXHAdSDKNativeAd *)nativeAd
                      adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    
}

/**
 信息流广告落地页被关闭
 
 @param nativeAd 广告实例
 */
- (void)CXH_nativeAdCloseLandingPage:(CXHAdSDKNativeAd *)nativeAd
                              adView:(__kindof UIView<CXHAdapterNativeAdViewDelegate> *)adView{
    
}

4.7 信息流模板插屏样式组件 - CXHAdSDKNativeInterstitialAd

信息流模板插屏样式组件是一种将信息流模板广告展示成插屏的组件,其中主要是将信息流广告展示成插屏的样式。用户可以直接调用展示方法展示广告。

信息流模板插屏样式组件 - CXHAdSDKNativeInterstitialAd:

@interface CXHAdSDKNativeInterstitialAd : NSObject

/**
 代理回调
*/
@property (nonatomic, weak) id<CXHAdSDKNativeInterstitialAdDelegate> delegate;

/*
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
 */
@property (nonatomic, weak) UIViewController *controller;

/**
 是否静音,默认静音
 */
@property (nonatomic, assign) BOOL isMuted;

/**
 信息流自动播放,默认WiFi自动播放 开启后WiFi/4G自动播放
 */
@property(nonatomic ,assign) BOOL autoPlay;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 插屏展示时间,对渠道广点通无效,默认为0(为0则需要用户手动关闭)
 */
@property (nonatomic, assign) NSInteger showTime;

/**
 广告是否准备好被展示
 */
- (BOOL)isAdValid;

/**
 展示广告,如果需要自定义布局,则修改.m文件中的setUpAdView函数
 */
- (void)showAdView;

/**
 加载广告
 */
- (void)loadAd:(NSString *)posId;

- (void)setAdScenes:(NSDictionary *)scenes;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

信息流模板插屏样式组件代理回调 - CXHAdSDKNativeInterstitialAdDelegate

@protocol CXHAdSDKNativeInterstitialAdDelegate <NSObject>

- (void)nativeInterstitialAdSuccessToLoad:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd;

- (void)nativeInterstitialAdFailedToLoad:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd;

- (void)nativeInterstitialAdExposure:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd;

- (void)nativeInterstitialAdClick:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd loadingPageURL:(NSString *)loadingPageURL;

- (void)nativeInterstitialAdClose:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd;

- (void)nativeInterstitialAdLoadingPageViewClose:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd;

@end

信息流模板插屏样式组件请求示例:

- (void)loadNativeInterstitialAd{
    CXHAdSDKNativeInterstitialAd *interAd = [[CXHAdSDKNativeInterstitialAd alloc]init];
    _interAd = interAd;
    _interAd.delegate = self;
    _interAd.controller = self;
    // 设置插屏广告的展示时长为5s,5s后自动消失
    _interAd.showTime = 5;
    [_interAd setAdScenes:@{
        @"station_id":@"无锡",
        @"in_out":@"1",
        @"userid":@"123",
    }];
    [_interAd loadAd:@"Screen_Insertion"];
  	// 查看价格,需要在设置广告位id之后调用
		NSLog(@"price----%ld", [_interAd getBidPrice]);
		// 发送竞价失败上报,此时的价格为第三方赢价的价格
		// [_interAd sendLossNotice:100];
		// 发送竞价成功上报
		[_interAd sendWinNotice:100]; 
}

#pragma mark - CXHAdSDKNativeInterstitialAdDelegate
- (void)nativeInterstitialAdSuccessToLoad:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd{
    [_interAd showAdView];
}

- (void)nativeInterstitialAdFailedToLoad:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd{
    
}

- (void)nativeInterstitialAdExposure:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd{
    
}

- (void)nativeInterstitialAdClick:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd loadingPageURL:(NSString *)loadingPageURL{
    
}

- (void)nativeInterstitialAdClose:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd{
    
}

- (void)nativeInterstitialAdLoadingPageViewClose:(CXHAdSDKNativeInterstitialAd *)nativeInterstitialAd{
    
}

4.8 服务类型广告 - CXHAdSDKServiceAdView

服务类型广告是指广告尺寸是定制的,与传统的横幅广告、信息流、开屏尺寸不一样,这里采用服务广告作为广告的承载容器。在接入该类型广告时,需要和服务方提前沟通,获取到定制的广告位id之后再进行广告请求。

服务类型广告 - CXHAdSDKServiceAdView:

@interface CXHAdSDKServiceAdView : UIView

/**
 广告生命周期代理
*/
@property (nonatomic, weak) id<CXHSDKServiceAdViewDelegate> delegate;

/**
 广告位id
*/
@property (nonatomic, copy) NSString *posId;

/**
 广告刷新时间间隔,30-120s之间.
*/
@property (nonatomic, assign) int refershTime;

/**
 是否展示关闭按钮,默认不展示,为YES则展示
*/
@property (nonatomic, assign) BOOL showCloseView;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
*/
@property (nonatomic, weak) UIViewController *controller;

- (id)new NS_UNAVAILABLE;
- (id)init NS_UNAVAILABLE;

/*
 初始化bannerView
 @param frame 期望的banner视图尺寸
*/
- (instancetype)initWithFrame:(CGRect)frame;

/**
 拉取并展示广告
*/
- (void)loadAndShow;

- (void)reloadData;

- (void)setAdScenes:(NSDictionary *)scenes;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

服务类型广告代理 - CXHSDKServiceAdViewDelegate

@protocol CXHSDKServiceAdViewDelegate <NSObject>

/**
 广告获取成功
 
 @param serviceAdView banner实例
 */
- (void)CXH_serviceAdViewDidReceived:(CXHAdSDKServiceAdView *)serviceAdView;

/**
 广告拉取失败
 
 @param serviceAdView banner实例
 @param error 错误描述
 */
- (void)CXH_serviceAdViewFailToReceived:(CXHAdSDKServiceAdView *)serviceAdView error:(NSError *)error;

/**
 广告点击
 
 @param serviceAdView 广告实例
 @param loadingPageURL 广告落地页地址,当渠道为bwt,并且customLoadingPage为YES时有值
 */
- (void)CXH_serviceAdViewClicked:(CXHAdSDKServiceAdView *)serviceAdView loadingPageURL:(NSString *)loadingPageURL;

/**
 广告关闭
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewClose:(CXHAdSDKServiceAdView *)serviceAdView;

/**
 广告展示
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewExposure:(CXHAdSDKServiceAdView *)serviceAdView;

/**
 关闭落地页
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewCloseLandingPage:(CXHAdSDKServiceAdView *)serviceAdView;

@end

服务类型广告请求示例:

#import <CXHAdSDK-Core/CXHAdSDK.h>
#import <CXHAdSDK-Core/CXHAdSDKServiceAdView.h>

// 1 初始化服务广告视图

_serviceAdView = [[CXHAdSDKServiceAdView alloc] initWithFrame:CGRectMake(0, 0, width, height)];
_serviceAdView.delegate = self;
_serviceAdView.controller = self;
_serviceAdView.refershTime = 35;
_serviceAdView.posId = @"87105193";
// _serviceAdView.showCloseView = YES;
_serviceAdView.backgroundColor = [UIColor whiteColor];

// 查看价格,需要在设置广告位id之后调用
NSLog(@"price----%ld", [_serviceAdView getBidPrice]);
// 发送竞价失败上报,此时的价格为第三方赢价的价格
// [_serviceAdView sendLossNotice:100];
// 发送竞价成功上报
[_serviceAdView sendWinNotice:100]; 
    
// 2 添加到父视图上
_serviceAdView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height  - height - 100, width, height);
[self.view addSubview:_serviceAdView];
    
// 3 加载并显示广告
[_serviceAdView loadAndShow];

// 4 代理回调
#pragma mark - CXHSDKServiceAdViewDelegate
/**
 广告获取成功
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewDidReceived:(CXHAdSDKServiceAdView *)serviceAdView{
    
}

/**
 广告拉取失败
 
 @param serviceAdView 广告实例
 @param error 错误描述
 */
- (void)CXH_serviceAdViewFailToReceived:(CXHAdSDKServiceAdView *)serviceAdView error:(NSError *)error{
    [_serviceAdView removeFromSuperview];
    _serviceAdView = nil;
}

/**
 广告点击
 
 @param serviceAdView 广告实例
 @param loadingPageURL 广告落地页地址,当渠道为bwt,并且customLoadingPage为YES时有值
 */
- (void)CXH_serviceAdViewClicked:(CXHAdSDKServiceAdView *)serviceAdView loadingPageURL:(NSString *)loadingPageURL{
    
}

/**
 广告关闭
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewClose:(CXHAdSDKServiceAdView *)serviceAdView{
    dispatch_async(dispatch_get_main_queue(), ^{
        _serviceAdView = nil;
    });
}

/**
 广告展示
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewExposure:(CXHAdSDKServiceAdView *)serviceAdView{
    
}

/**
 关闭落地页
 
 @param serviceAdView 广告实例
 */
- (void)CXH_serviceAdViewCloseLandingPage:(CXHAdSDKServiceAdView *)serviceAdView{
    
}

4.9 开屏广告 - CXHAdSDKSplashAd

开屏广告会在您的应用开启时加载展示,拥有固定展示时间,展示完毕后自动关闭并进入您的应用主界面。

开屏广告建议在闪屏页进行展示,开屏广告的宽度和高度取决于容器的宽高,都是会撑满广告容器;开屏广告的高度必须大于等于屏幕高度(手机屏幕完整高度,包括状态栏之类)的75%,否则可能会影响收益计费。

推荐在 AppDelegatedidFinishLaunchingWithOptions方法的 return YES之前调用开屏。

开屏广告 - CXHAdSDKSplashAd:

@interface CXHAdSDKSplashAd : NSObject

/**
 广告生命周期代理
*/
@property (nonatomic, weak) id<CXHAdSDKSplashAdDelegate> delegate;

/**
 广告位id
*/
@property (nonatomic, copy) NSString *posId;

/**
 *  广告是否有效,以下情况会返回NO,建议在展示广告之前判断,否则会影响计费或展示失败
 *  a.广告未拉取成功
 *  b.广告已经曝光过
 *  c.广告过期
 *
 */
@property (nonatomic, readonly) BOOL isAdValid;

/**
 自定义处理广告落地页,当渠道为bwt时有效,点击回调中会带有广告落地页地址
*/
@property (nonatomic, assign) BOOL customLoadingPage;

/**
 展示时间,对渠道广点通无效,默认为5s
 */
@property (nonatomic, assign) NSInteger showTime;

/**
 设置广告跳过按钮位置,默认为右下角,只针对channel和zhike渠道
 */
@property (nonatomic, assign) BOOL setSkipButtonToRightTop;

/// 开屏广告的背景图片, 可以设置背景图片作为开屏加载时的默认背景
@property (nonatomic, strong) UIImage *backgroundImage;

/**
 开屏广告底部视图
 */
@property (nonatomic, strong) UIView *bottomView;

/**
 viewControllerForPresentingModalView
 详解:[必选]开发者需传入用来弹出目标页的ViewController,一般为当前ViewController
 */
@property (nonatomic, weak) UIViewController *controller;

/**
 广告发起请求并展示在Window中
 */
- (void)loadAndShowSplashAdInWindow:(UIWindow *)window;

/**
 请求开屏广告,只拉取不展示
 */
- (void)loadSplashAd;

/**
 展示开屏广告
 */
- (void)showSplashAdInWindow:(UIWindow *)window;

/**
 设置开屏场景id
 */
- (void)setSplashAdScenes:(NSDictionary *)scenes;

/**
 获取竞价价格,单位分,为0则表示不支持竞价,开启该功能需要联系媒介商务
 */
- (NSInteger)getBidPrice;
/**
 发送竞价成功上报
 @param price 赢价价格,单位分
 */
- (void)sendWinNotice:(NSInteger)price;

/**
 发送竞价失败上报
 @param price 赢价价格,单位分
 */
- (void)sendLossNotice:(NSInteger)price;

@end

开屏广告代理 - CXHAdSDKSplashAdDelegate

@protocol CXHAdSDKSplashAdDelegate <NSObject>

@optional

/**
 开屏广告点击回调, 可能会打开 AppStore, WebView, ThirdApp etc.

 @param splashAd 开屏广告
 @param loadingPageURL 广告落地页地址,当渠道为bwt,并且customLoadingPage为YES时有值
 */
- (void)CXH_splashAdDidClick:(CXHAdSDKSplashAd *)splashAd loadingPageURL:(NSString *)loadingPageURL;

/**
 开屏广告关闭回调, 触发条件: 点击广告, 点击跳过, 超时关闭

 @param splashAd 开屏对象
 */
- (void)CXH_splashAdDidClose:(CXHAdSDKSplashAd *)splashAd;

/**
 开屏广告展示回调

 @param splashAd 开屏对象
 */
- (void)CXH_splashAdExposured:(CXHAdSDKSplashAd *)splashAd;

/**
 开屏广告加载成功
 
 @param splashAd 开屏对象
 */
- (void)CXH_splashAdDidLoad:(CXHAdSDKSplashAd *)splashAd;

/**
 开屏广告加载失败
 
 @param splashAd 开屏对象
 */
- (void)CXH_splashAdDidFailToLoad:(CXHAdSDKSplashAd *)splashAd error:(NSError *)error;

/**
 *  开屏广告成功展示
 *
 *  @param splashAd 开屏对象
 */
- (void)CXH_splashAdSuccessPresentScreen:(CXHAdSDKSplashAd *)splashAd;

/**
 *  开屏广告展示失败
 *
 *  @param splashAd 开屏对象
 */
- (void)CXH_splashAdFailToPresent:(CXHAdSDKSplashAd *)splashAd withError:(NSError *)error;

/**
 *  开屏广告关闭落地页
 *
 *  @param splashAd 开屏对象
 */
- (void)CXH_splashAdCloseLandingPage:(CXHAdSDKSplashAd *)splashAd;

@end

开屏广告请求示例:

// 1、初始化开屏广告
    self.splashAd = [[CXHAdSDKSplashAd alloc]init];
    self.splashAd.delegate = self;
    self.splashAd.showTime = 5;
    self.splashAd.controller = _window.rootViewController;
    self.splashAd.setSkipButtonToRightTop = YES;
    // 2、设置posId
    self.splashAd.posId = @"88437632";
    // 3、设置默认启动图(一般设置启动图的平铺颜色为背景颜色,使得视觉效果更加平滑)
    self.splashAd.backgroundImage = [UIImage imageNamed:@"750x1334.png"];

		// 查看价格,需要在设置广告位id之后调用
		NSLog(@"price----%ld", [self.splashAd getBidPrice]);
		// 发送竞价失败上报,此时的价格为第三方赢价的价格
		// [self.splashAd sendLossNotice:100];
		// 发送竞价成功上报
		[self.splashAd sendWinNotice:100]; 
    
    // 4、开屏广告机型适配
    CGFloat bottomViewHeight;
    if (kCXHCurveScreen) { // 刘海屏
        bottomViewHeight = [UIScreen mainScreen].bounds.size.height * 0.15;
    } else {
        bottomViewHeight = [UIScreen mainScreen].bounds.size.height - [UIScreen mainScreen].bounds.size.width * (960 / 640.0);
    }
    // 5、底部视图设置,非必选项
    UIView *bottomView = [[UIView alloc] init];
    bottomView.backgroundColor = [UIColor whiteColor];
    bottomView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, bottomViewHeight);
    UIImageView *logoImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"LOGO.png"]];
    logoImageView.frame = CGRectMake(([UIScreen mainScreen].bounds.size.width - 311)/ 2, (bottomViewHeight - 47)/2, 311, 47);
    [bottomView addSubview:logoImageView];
    self.splashAd.bottomView = bottomView;
    [self.splashAd loadAndShowSplashAdInWindow:self.window];
}

#pragma mark - CXHAdSDKSplashAdDelegate
/**
 开屏广告点击回调, 可能会打开 AppStore, WebView, ThirdApp etc.

 @param splashAd 开屏广告
 @param loadingPageURL 广告落地页地址,当渠道为bwt,并且customLoadingPage为YES时有值
 */
- (void)CXH_splashAdDidClick:(CXHAdSDKSplashAd *)splashAd loadingPageURL:(NSString *)loadingPageURL{
    
}

/**
 开屏广告关闭回调, 触发条件: 点击广告, 点击跳过, 超时关闭

 @param splashAd 开屏对象
 */
- (void)CXH_splashAdDidClose:(CXHAdSDKSplashAd *)splashAd{
    self.splashAd = nil;
}

/**
 开屏广告展示回调

 @param splashAd 开屏对象
 */
- (void)CXH_splashAdExposured:(CXHAdSDKSplashAd *)splashAd{
    
}

/**
 开屏广告加载成功
 
 @param splashAd 开屏对象
 */
- (void)CXH_splashAdDidLoad:(CXHAdSDKSplashAd *)splashAd{
    
}

/**
 开屏广告加载失败
 
 @param splashAd 开屏对象
 */
- (void)CXH_splashAdDidFailToLoad:(CXHAdSDKSplashAd *)splashAd error:(NSError *)error{
    
}

/**
 *  开屏广告成功展示
 *
 *  @param splashAd 开屏对象
 */
- (void)CXH_splashAdSuccessPresentScreen:(CXHAdSDKSplashAd *)splashAd{
    
}

/**
 *  开屏广告展示失败
 *
 *  @param splashAd 开屏对象
 */
- (void)CXH_splashAdFailToPresent:(CXHAdSDKSplashAd *)splashAd withError:(NSError *)error{
    
}

/**
 *  开屏广告关闭落地页
 *
 *  @param splashAd 开屏对象
 */
- (void)CXH_splashAdCloseLandingPage:(CXHAdSDKSplashAd *)splashAd{
    
}

##错误码说明

错误码 描述
100101 SDK初始化时APPID为空
100103 SDK初始化时请求配置出错或者返回配置为空(麻烦检查网络或者提供appid给到对接人员)
100107 SDK平台配置为空(提供appid给到对接人员)
100108 未请求到广告(重试多次未成功请将appid和posid给到对接人员)或者广告渲染失败
Copyright (c) 2022 华资融创 <10675175+huazi-rongchuang@user.noreply.gitee.com> Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

程序化广告聚合SDK-iOS,包含多个平台 展开 收起
Objective-C 等 3 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/huazi-rongchuang/cxhadsdk.git
git@gitee.com:huazi-rongchuang/cxhadsdk.git
huazi-rongchuang
cxhadsdk
CXHAdSDK
master

搜索帮助