Skip to main content

标准原生

前提条件#

  • 接入TradPlus SDK
  • 初始化TradPlus SDK
  • 在TradPlus后台创建原生广告位
  1. 添加⼀一个MsNativeAdView的属性。
@property (strong, nonatomic) MsNativeAdView *nativeAd;
  1. 创建原生广告,进行加载。
_nativeAd = [[MsNativeAdView alloc] init];
_nativeAd.frame = self.adView.bounds;
[_nativeAd setAdUnitID:@"0AA7414819EE56542DBA126FE5A19C7E"];
// Set a delegate to get notified when the ad was loaded.
_nativeAd.delegate = self;
//这个必须要设置
_nativeAd.renderingViewClass = [AdvancedNativeAdViewSample class];
[self.adView addSubview:_nativeAd];
[_nativeAd loadAd];

原生需新建一个类,设置给上面提到的renderingViewClass参数,继承UIView,参照demo⾥的 AdvancedNativeAdViewSample。

  1. 实现delegate方法,监听广告状态。
-(void)nativeAdLoaded:(MsNativeAdView *)nativeAd;
-(void)nativeAd:(MsNativeAdView *)nativeAd didFailWithError:(NSError *)error;
-(void)nativeAdClicked:(MsNativeAdView *)nativeAd;
- (void)nativeAdBidStart:(MsNativeAdView *)nativeAd;
- (void)nativeAdBidEnd:(MsNativeAdView *)nativeAd;
- (void)nativeAdLoadStart:(MsNativeAdView *)nativeAd;
- (void)nativeAdAllLoaded:(MsNativeAdView *)nativeAd;