「Mopub Mediation Banner」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: 依照Mopub設定教學設定後,開始實做Custom event<br> 官方教學:[https://github.com/mopub/mopub-ios-sdk/wiki/Custom-Events 連結]<br> 1.先建立一cl...)
 
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 5 次修訂)
行 1: 行 1:
依照[[Mopub Setting|Mopub設定教學]]設定後,開始實做Custom event<br>
依照[[Mopub Setting|Mopub設定教學]]設定後,開始實做Custom event<br>
官方教學:[https://github.com/mopub/mopub-ios-sdk/wiki/Custom-Events 連結]<br>
官方教學:[https://github.com/mopub/mopub-ios-sdk/wiki/Custom-Events 連結]<br>
1.先建立一class繼承MPBannerCustomEvent<br>
1.先建立一class繼承MPBannerCustomEvent,class名稱必須與Mopub設定內一樣<br>
2.加入Tamedia TADBannerView.h<br>
2.加入#import <TAMediaAdsFramework/TAMediaAdsFramework.h> <br>
3.複寫<code>- (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info</code>以及在此method內用TADBannerView呼叫廣告<br>
3.複寫<code>- (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info</code>以及在此method內用TADBannerView呼叫廣告<br>
4.在TADBannerView delegate內呼叫MPBannerCustomEvent delegate執行相對應的method<br>
可參考以下代碼
可參考以下代碼


== CustomBannerEvent ==
[[MoPub Mediation Setting|回MoPub教學]]
   '''//  CustomBannerEvent.h'''
 
== TAMediaCustomBannerEvent ==
   '''//  TAMediaCustomBannerEvent.h'''
   //匯入TADBannerVIew
   //匯入TADBannerVIew
   #import "MPBannerCustomEvent.h"
   #import "MPBannerCustomEvent.h"
   #import "TADBannerView.h"
   #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
   @interface CustomBannerEvent : MPBannerCustomEvent<TADBannerViewDelegate>
 
   @interface TAMediaCustomBannerEvent : MPBannerCustomEvent<TADBannerViewDelegate>
   @property (nonatomic, strong) TADBannerView *bannerView;
   @property (nonatomic, strong) TADBannerView *bannerView;
   @end
   @end


   #import "CustomBannerEvent.h"
   #import "TAMediaCustomBannerEvent.h"
    
    
   @implementation CustomBannerEvent
   @implementation TAMediaCustomBannerEvent
    
    
   - (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info {
   - (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info {
行 23: 行 27:
       request.testing = NO;
       request.testing = NO;
       request.gender = kTADGenderUnknown;
       request.gender = kTADGenderUnknown;
       [request setBirthdayWithYear:1988 month:6 day:11];
       [request setBirthdayWithYear:xxxx month:xx day:xx];
       [request setLocationWithLatitude:25.033534 longitude:121.534791 accuracy:1];
       [request setLocationWithLatitude:25.033534 longitude:121.534791 accuracy:1];
       if (!self.bannerView) {
       if (!self.bannerView) {

於 2018年8月21日 (二) 02:49 的最新修訂

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

回MoPub教學

TAMediaCustomBannerEvent

  //  TAMediaCustomBannerEvent.h
  //匯入TADBannerVIew
  #import "MPBannerCustomEvent.h"
  #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
  
  @interface TAMediaCustomBannerEvent : MPBannerCustomEvent<TADBannerViewDelegate>
  @property (nonatomic, strong) TADBannerView *bannerView;
  @end
  #import "TAMediaCustomBannerEvent.h"
  
  @implementation TAMediaCustomBannerEvent
  
  - (void)requestAdWithSize:(CGSize)size customEventInfo:(NSDictionary *)info {
      TADRequest *request = [TADRequest request];
      request.testing = NO;
      request.gender = kTADGenderUnknown;
      [request setBirthdayWithYear:xxxx month:xx day:xx];
      [request setLocationWithLatitude:25.033534 longitude:121.534791 accuracy:1];
      if (!self.bannerView) {
          self.bannerView = [[TADBannerView alloc] initWithAdSize:TADAdSizeFromCGSize(size)];
      }
      self.bannerView.delegate = self;
      self.bannerView.turnOnMicrophone = NO;
      NSString *bannerId = info[@"BannerId"];//此處BannerId是在Mopub內設定
      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(bannerCustomEvent:didLoadAd:)]) {
          [self.delegate bannerCustomEvent:self didLoadAd:view];
      }
  }
  - (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(TADRequestError *)error {
      if ([self.delegate respondsToSelector:@selector(bannerCustomEvent:didFailToLoadAdWithError:)]) {
          [self.delegate bannerCustomEvent:self didFailToLoadAdWithError:error];
      }
  }
  
  - (void)adViewWillPresentScreen:(TADBannerView *)adView {       
  }
  
  - (void)adViewWillDismissScreen:(TADBannerView *)adView {       
  }
  
  - (void)adViewDidDismissScreen:(TADBannerView *)adView {       
  }
  
  - (void)adViewWillLeaveApplication:(TADBannerView *)adView {
      if ([self.delegate respondsToSelector:@selector(bannerCustomEventWillLeaveApplication:)]) {
          [self.delegate bannerCustomEventWillLeaveApplication:self];
      }
  }   
  - (void)dealloc {
      if (self.bannerView != nil) {
          self.bannerView.delegate = nil;
          self.bannerView = nil;
      }
  }   
  @end