主题
信息流广告
1. 主要API
1.1 ApexAdxNativeAdManager
| 方法名 | 方法介绍 |
|---|---|
| - (instancetype)initWithRequest:(ApexAdxAdRequest *)request | 初始化方法。参数说明:request(广告请求对象)。 |
| - (void)loadAdsWithCount:(NSInteger)count | 请求广告。参数说明:count(一次请求广告数量,数值区间[1,3])。 |
| - (NSArray<ApexAdxNativeAd *> * _Nullable)allNativeAds | 广告拉取成功后,获取广告集合。 |
1.2 ApexAdxAdRequest
| 参数名 | 类型 | 描述 |
|---|---|---|
| userId | NSString | 可选,用户Id |
| pid | NSString | 必传,广告位ID |
| options | NSDictionary<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 *)reason | dislike弹窗选择后的回调,有穿山甲广告源时,必须在该方法里移除广告 |
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掉广告,否则有些广告会无法关闭,影响收益。