Skip to main content

标准原生(v6.4+)

前提条件#

  • 接入TradPlus SDK
  • 初始化TradPlus SDK
  • 在TradPlus后台创建原生广告位
  1. 添加⼀一个TradPlusAdNative的属性。
#import <TradPlusAds/TradPlusAdNative.h>
@property (strong, nonatomic) TradPlusAdNative *nativeAd;
  1. 加载广告
//初始化广告位
self.nativeAd = [[TradPlusAdNative alloc] init];
[self.nativeAd setAdUnitID:@"您的广告位ID"];
//设置 原生模版类广告的加载尺寸(可选)
[self.nativeAd setTemplateRenderSize:CGSizeMake(320, 200)];
//下载完资源成后通知load完成(可选)
self.nativeAd.finishDownload = YES;
//设置回调
self.nativeAd.delegate = self;
//加载广告
[self.nativeAd loadAd];
  1. 显示广告

    原生需要 RenderingViewClass,继承UIView, RenderingViewClass 需要实现 TradPlusNativeAdRendering 协议 可参照 Demo 中的 TPNativeTemplate

//传入RenderingViewClass 及 subview
//sceneId为广告场景ID
[self.nativeAd showADWithRenderingViewClass:[RenderingViewClass class] subview:self.adView sceneId:nil];
  1. 实现delegate方法,监听广告状态 回调信息说明
//AD加载完成
- (void)tpNativeAdLoaded:(NSDictionary *)adInfo;
//AD加载失败
- (void)tpNativeAdLoadFailWithError:(NSError *)error;
//AD展现
- (void)tpNativeAdImpression:(NSDictionary *)adInfo;
//AD展现失败
- (void)tpNativeAdShow:(NSDictionary *)adInfo didFailWithError:(NSError *)error;
//AD被点击
- (void)tpNativeAdClicked:(NSDictionary *)adInfo;
//为三方提供rootviewController 用于点击广告后的操作
- (UIViewController *)viewControllerForPresentingModalView;
//AD被关闭 部分模版类回调通知
- (void)tpNativeAdClose:(NSDictionary *)adInfo;
//bidding开始
- (void)tpNativeAdBidStart:(NSDictionary *)adInfo;
//bidding结束
- (void)tpNativeAdBidEnd:(NSDictionary *)adInfo success:(BOOL)success;
//开始加载
- (void)tpNativeAdLoadStart:(NSDictionary *)adInfo;
//多缓存情况下,当每个广告源加载成功后会都会回调一次。
- (void)tpNativeAdOneLayerLoaded:(NSDictionary *)adInfo;
//多缓存情况下,当每个广告源加载失败后会都会回调一次。
- (void)tpNativeAdOneLayerLoad:(NSDictionary *)adInfo didFailWithError:(NSError *)error;
//加载流程全部结束
- (void)tpNativeAdAllLoaded:(BOOL)success;

自定义view 渲染方式(可选)#

//初始化自定义UIView
TPNativeTemplate *nativeView = [[NSBundle mainBundle] loadNibNamed:@"TPNativeView" owner:self options:nil].lastObject;
nativeView.frame = self.adView.bounds;
[self.adView addSubview:nativeView];
//自行设置渲染元素 以及 元素是否可点击
TradPlusNativeRenderer *nativeRenderer = [[TradPlusNativeRenderer alloc] init];
[nativeRenderer setTitleLable:nativeView.titleLabel canClick:YES];
[nativeRenderer setTextLable:nativeView.textLabel canClick:YES];
[nativeRenderer setCtaLable:nativeView.ctaLabel canClick:YES];
[nativeRenderer setIconView:nativeView.iconImageView canClick:YES];
[nativeRenderer setMainImageView:nativeView.mainImageView canClick:YES];
[nativeRenderer setAdChoiceImageView:nativeView.adChoiceImageView canClick:YES];
[nativeRenderer setAdView:nativeView canClick:YES];
//设置Renderer 及 subview
//sceneId为广告场景ID
[self.nativeAd showADWithNativeRenderer:nativeRenderer subview:self.adView sceneId:nil];