「Mopub Mediation Adapter Banner」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
imported>Wikiuser
 
行 1: 行 1:
依照[[Mopub Setting|Mopub設定教學]]設定後,開始實做 Adapter <br>
依照 [[Mopub Setting|Mopub設定教學]] 設定後,開始實做 Adapter <br>
官方教學:[https://developers.mopub.com/networks/integrate/build-adapters-ios/#quick-start-for-inline-ads 連結]<br>
官方教學:[https://developers.mopub.com/networks/integrate/build-adapters-ios/#quick-start-for-inline-ads 連結]<br>
1.先建立一 class 繼承 MPInlineAdAdapter,class 名稱必須與 Mopub 後台設定內一樣<br>
1.先建立一 class 繼承 MPInlineAdAdapter,class 名稱必須與 Mopub 後台設定內一樣<br>

於 2021年5月19日 (三) 11:41 的最新修訂

依照 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
可參考以下代碼,或直接下載 adapter 檔直接加入專案中

回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