Skip to content

信息流广告

1. 主要API

1.1 ApexAdxNativeAdManager

方法名方法介绍
- (instancetype)initWithRequest:(ApexAdxAdRequest *)request初始化方法。参数说明:request(广告请求对象)。
- (void)loadAdsWithCount:(NSInteger)count请求广告。参数说明:count(一次请求广告数量,数值区间[1,3])。
- (NSArray<ApexAdxNativeAd *> * _Nullable)allNativeAds广告拉取成功后,获取广告集合。

1.2 ApexAdxAdRequest

参数名类型描述
userIdNSString可选,用户Id
pidNSString必传,广告位ID
optionsNSDictionary<NSString *, NSString *>可选,服务端激励回传时,透传参数

1.3 ApexAdxNativeAdManagerDelegate

方法名方法介绍
- (void)nativeAdManagerDidLoad:(ApexAdxNativeAdManager *)nativeAdsManager广告成功加载。参数说明:nativeAdsManager(参考1.1)。
- (void)nativeAdManagerDidFailWithError:(NSError *)error广告加载失败。参数说明:error(报错信息)。

1.4 ApexAdxNativeAdView

方法名方法介绍
+ (instancetype)adView初始化方法。
- (void)renderNativeAd:(ApexAdxNativeAd *)nativeAd刷新广告数据
- (UIView *)adView获取View

1.5 ApexAdxNativeAdViewDelegate

方法名方法介绍
- (void)nativeAdViewDidRenderSuccess:(ApexAdxNativeAdView *)nativeAdView广告渲染成功
- (void)nativeAdViewDidFailToRender:(NSError *)error广告渲染失败。
- (void)nativeAdViewDidClick广告点击回调
- (void)nativeAdViewDidDislike:(NSString *)reasondislike弹窗选择后的回调,有穿山甲广告源时,必须在该方法里移除广告

2. 接入代码示例

2.1 信息流广告加载

objective-c
ApexAdxAdRequest *request = [ApexAdxAdRequest request];
request.pid = @"广告位id";
request.userId = @"用户id";
if (self.nativeAdManager == nil) {
    self.nativeAdManager = [[ApexAdxNativeAdManager alloc] initWithRequest:request];
}
self.nativeAdManager.delegate = self;
self.nativeAdManager.adSize = CGSizeMake(320, 150);
[self.nativeAdManager loadAdsWithCount:1];

2.2 原生广告展示

objective-c
self.adView = [ApexAdxNativeAdView adView];
UIViewController *rootViewController = [ApexAdxUtil getCurrentController];
[adContainer addSubview:self.adView.getView];
// 调整广告view的frame
self.adView.frame = adContainer.bounds;
self.adView.delegate = self;
self.adView.viewController = rootViewController;
[self.adView renderNativeAd:self.nativeAd];

2.3 注意事项

重要提示

穿山甲信息流关闭时,需要在 - (void)nativeAdViewDidDislike:(NSString *)reason 回调方法里,主动remove掉广告,否则有些广告会无法关闭,影响收益。

ApexAdx SDK Documentation