Skip to main content

原生信息流

前提条件#

  • 接入TradPlus SDK
  • 初始化TradPlus SDK
  • 在TradPlus后台创建原生广告位 根据需要选择标准原生或原生横幅
  1. 添加一个MsNativeAdsLoader的属性。
@interface NativeHTViewController ()
@property (strong, nonatomic) MsNativeAdsLoader *adsLoader;
  1. 创建原生广告,进行加载。
_adsLoader = [[MsNativeAdsLoader alloc] init];
_adsLoader.delegate = self;
_adsLoader.defaultRenderingViewClass = [AdvancedNativeAdViewSample class];
//有道专用
_adsLoader.YDRenderingViewClass = [YouDaoNativeAdView class];
[_adsLoader setAdUnitID:_placementId];
//设置想获得的原生广告个数
[_adsLoader loadAds:2];
}```
原生需新建一个类,设置给上面提到的renderingViewClass参数,继承UIView,参照demo⾥的 AdvancedNativeAdViewSample。
1. 实现delegate方法,监听广告状态。
```objc
//整个TradPlus广告位加载结束。
- (void)nativeAdsAllLoaded:(BOOL)isAdReady readyAds:(nonnull NSArray *)readyAds error:(nonnull NSError *)error {
MSLogInfo(@"nativeAdsAllLoaded->ready count:%d", readyAds.count);
if (isAdReady)
{
for (int i = 0; i < readyAds.count;i++)
{
MSNativeAd *nativeAd = readyAds[i];
MSLogInfo(@"nativeAd.properties:%@", nativeAd.properties);
NSString *type = [nativeAd.properties objectForKey:@"type"];
UIView *adView;
if (type && [type isEqualToString:@"facebook"])
adView = [nativeAd retrieveAdViewWithError:[AdvancedNativeAdViewSampleFB class] error:nil];
else if (type && [type isEqualToString:@"admob"])
adView = [nativeAd retrieveAdViewWithError:[AdvancedNativeAdViewSampleGG class] error:nil];
else if (type && [type isEqualToString:@"pangle"])
adView = [nativeAd retrieveAdViewWithError:[AdvancedNativeAdViewSampleGG class] error:nil];
else if (type && [type isEqualToString:@"youdao"])
adView = [nativeAd retrieveYDAdViewWithError:nil];
else
adView = [nativeAd retrieveAdViewWithError:[AdvancedNativeAdViewSampleGG class] error:nil];
}
}
}