Mopub Mediation Adapter Banner

出自TAMedia
於 2021年5月19日 (三) 09:21 由 imported>Wikiuser 所做的修訂 (新頁面: 依照Mopub設定教學設定後,開始實做 Adapter <br> 官方教學:[https://developers.mopub.com/networks/integrate/build-adapters-ios/#quick-start-for-inlin...)
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
跳至導覽 跳至搜尋

依照Mopub設定教學設定後,開始實做 Adapter
官方教學:連結
1.先建立一 class 繼承 MPInlineAdAdapter,class 名稱必須與 Mopub 後台設定內一樣
2.加入 #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
3.複寫 - (void)requestAdWithSize:(CGSize) adapterInfo: adMarkup:以及在此method內用TADBannerView呼叫廣告
4.在 TADBannerView delegate內呼叫MPInlineAdAdapterDelegate執行相對應的method
可參考以下代碼

回MoPub教學

TAMediaInlineAdAdaptor

 #import <MoPub/MoPub.h>
 #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
 @interface TAMediaInlineAdAdaptor : MPInlineAdAdapter<MPThirdPartyInlineAdAdapter, TADBannerViewDelegate>
 @property (nonatomic, strong) TADBannerView *bannerView;
 @end
 
 #import "TAMediaInlineAdAdaptor.h"
 
 @implementation TAMediaInlineAdAdaptor
 
 - (void)requestAdWithSize:(CGSize)size adapterInfo:(NSDictionary *)info adMarkup:(NSString *)adMarkup {
     TADRequest *request = [TADRequest request];
     request.testing = NO;
     request.gender = kTADGenderUnknown;
 
     if (!self.bannerView) {
         self.bannerView = [[TADBannerView alloc] initWithAdSize:TADAdSizeFromCGSize(size)];
     }
     self.bannerView.delegate = self;
     self.bannerView.turnOnMicrophone = NO;
     NSString *bannerId = info[@"omBannerId"];
     self.bannerView.adUnitID = bannerId;
     self.bannerView.rootViewController = [[UIApplication sharedApplication] keyWindow].rootViewController;
     [self.bannerView loadRequest:request];
 }
 
 #pragma mark - [TAmedia Banner delegate]
 
 - (void)adViewDidReceiveAd:(TADBannerView *)view {
     if ([self.delegate respondsToSelector:@selector(inlineAdAdapter:didLoadAdWithAdView:)]) {
         [self.delegate inlineAdAdapter:self didLoadAdWithAdView:view];
     }
 }
 - (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(TADRequestError *)error {
     if ([self.delegate respondsToSelector:@selector(inlineAdAdapter:didFailToLoadAdWithError:)]) {
         [self.delegate inlineAdAdapter:self didFailToLoadAdWithError:error];
     }
 }
 
 - (void)adViewWillPresentScreen:(TADBannerView *)adView {
  }
 - (void)adViewWillDismissScreen:(TADBannerView *)adView {
  }
 - (void)adViewDidDismissScreen:(TADBannerView *)adView {
  }
 
 - (void)adViewWillLeaveApplication:(TADBannerView *)adView {
     if ([self.delegate respondsToSelector:@selector(inlineAdAdapterWillLeaveApplication:)]) {
         [self.delegate inlineAdAdapterWillLeaveApplication:self];
     }
 }
 
 - (void)dealloc {
     if (self.bannerView != nil) {
         self.bannerView.delegate = nil;
         self.bannerView = nil;
     }
 }
 
 @end