「Mopub Mediation Interstitial」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 2 次修訂)
行 2: 行 2:
官方教學:[https://github.com/mopub/mopub-ios-sdk/wiki/Custom-Events 連結]<br>
官方教學:[https://github.com/mopub/mopub-ios-sdk/wiki/Custom-Events 連結]<br>
1.先建立一class繼承MPInterstitialCustomEvent,class名稱必須與Mopub設定內一樣<br>
1.先建立一class繼承MPInterstitialCustomEvent,class名稱必須與Mopub設定內一樣<br>
2.加入Tamedia TADInterstitial.h<br>
2.加入#import <TAMediaAdsFramework/TAMediaAdsFramework.h>
3.複寫<code>-requestInterstitialWithCustomEventInfo:</code>以及在此method內用TADInterstitial呼叫廣告<br>
3.複寫<code>-requestInterstitialWithCustomEventInfo:</code>以及在此method內用TADInterstitial呼叫廣告<br>
4.複寫<code>-showInterstitialFromRootViewController:</code>以及在此method內用TADInterstitial的方法<code>-presentFromRootViewController:</code>顯示廣告<br>
4.複寫<code>-showInterstitialFromRootViewController:</code>以及在此method內用TADInterstitial的方法<code>-presentFromRootViewController:</code>顯示廣告<br>
行 12: 行 12:
== TAMediaCustomInterstitialEvent ==
== TAMediaCustomInterstitialEvent ==
   #import "MPInterstitialCustomEvent.h"
   #import "MPInterstitialCustomEvent.h"
   #import "TADInterstitial.h"
   #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
    
    
   @interface TAMediaCustomInterstitialEvent : MPInterstitialCustomEvent <TADInterstitialDelegate>
   @interface TAMediaCustomInterstitialEvent : MPInterstitialCustomEvent <TADInterstitialDelegate>
行 31: 行 31:
       request.gender = kTADGenderUnknown;       
       request.gender = kTADGenderUnknown;       
       // Set birthday
       // Set birthday
       [request setBirthdayWithYear:1988 month:6 day:11];     
       [request setBirthdayWithYear:xxxx month:xx day:xx];     
       // Set location
       // Set location
       [request setLocationWithLatitude:25.033534 longitude:121.534791 accuracy:1];
       [request setLocationWithLatitude:25.033534 longitude:121.534791 accuracy:1];
行 98: 行 98:
           [self.delegate interstitialCustomEventWillLeaveApplication:self];
           [self.delegate interstitialCustomEventWillLeaveApplication:self];
       }
       }
  }  
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEventDidReceiveTapEvent:)]) {
          [self.delegate interstitialCustomEventDidReceiveTapEvent:self];
      }
      }  
    
    
   - (void)dealloc {
   - (void)dealloc {

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

依照Mopub設定教學設定後,開始實做Custom event
官方教學:連結
1.先建立一class繼承MPInterstitialCustomEvent,class名稱必須與Mopub設定內一樣
2.加入#import <TAMediaAdsFramework/TAMediaAdsFramework.h> 3.複寫-requestInterstitialWithCustomEventInfo:以及在此method內用TADInterstitial呼叫廣告
4.複寫-showInterstitialFromRootViewController:以及在此method內用TADInterstitial的方法-presentFromRootViewController:顯示廣告
5.TADInterstitial的delegate內呼叫MPInterstitialCustomEvent delegate執行對應的method
可參考以下代碼

回MoPub教學

TAMediaCustomInterstitialEvent

  #import "MPInterstitialCustomEvent.h"
  #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
  
  @interface TAMediaCustomInterstitialEvent : MPInterstitialCustomEvent <TADInterstitialDelegate>
  
  @property (nonatomic,strong) TADInterstitial *interstitialView;
  
  @end
  #import "TAMediaCustomInterstitialEvent.h"
  
  @implementation TAMediaCustomInterstitialEvent
  
  - (void)requestInterstitialWithCustomEventInfo:(NSDictionary *)info {
      TADRequest *request = [TADRequest request];
      
      request.testing = NO;
      // Type: TADGender
      request.gender = kTADGenderUnknown;       
      // Set birthday
      [request setBirthdayWithYear:xxxx month:xx day:xx];    
      // Set location
      [request setLocationWithLatitude:25.033534 longitude:121.534791 accuracy:1];
      
      // interstitialView 物件初始化
      if (self.interstitialView == nil) {
          self.interstitialView = [[TADInterstitial alloc] init];
      } 
      // 必須要設定delegate
      self.interstitialView.delegate = self;
      
      // 設定 AD Unit ID
      NSString *interstitialId = info[@"InterstitialId"];//此處InterstitialId是在Mopub內設定
      self.interstitialView.adUnitID = interstitialId;
      self.interstitialView.turnOnMicrophone = NO;
      
      // 載入廣告
      [self.interstitialView loadRequest:request];
  }
  
  - (void)showInterstitialFromRootViewController:(UIViewController *)rootViewController {
      [self.interstitialView presentFromRootViewController:rootViewController];
  }
   
  // Interstitial廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告
  - (void)interstitialDidReceiveAd:(TADInterstitial *)ad {    
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEvent:didLoadAd:)]) {
          [self.delegate interstitialCustomEvent:self didLoadAd:ad];
      }
   }
  
  // Interstitial廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息
  - (void)interstitial:(TADInterstitial *)ad didFailToReceiveAdWithError:(TADRequestError *)error {
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEvent:didFailToLoadAdWithError:)]) {
          [self.delegate interstitialCustomEvent:self didFailToLoadAdWithError:error];
      }
  }
  
  // Interstitial廣告呈現之前呼叫, 注意使用者可能會在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式, 可以在這function中處理該暫停之項目
  - (void)interstitialWillPresentScreen:(TADInterstitial *)ad {
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEventWillAppear:)]) {
          [self.delegate interstitialCustomEventWillAppear:self];
      }
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEventDidAppear:)]) {
          [self.delegate interstitialCustomEventDidAppear:self];
      }
  }
  
  // Interstitial廣告關閉, 在螢幕上消失之前呼叫, 再次提醒在Interstitail消失前, 必須將Interstitial及delegate設為nil (可以在這個function中執行)
  - (void)interstitialWillDismissScreen:(TADInterstitial *)ad {
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEventWillDisappear:)]) {
          [self.delegate interstitialCustomEventWillDisappear:self];
      }    
  }
  
  // Interstitial廣告關閉, 在螢幕上消失之後呼叫
  - (void)interstitialDidDismissScreen:(TADInterstitial *)ad {
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEventDidDisappear:)]) {
          [self.delegate interstitialCustomEventDidDisappear:self];
      }    
  }
  
  // 使用者在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式之前呼叫
  - (void)interstitialWillLeaveApplication:(TADInterstitial *)ad {
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEventWillLeaveApplication:)]) {
          [self.delegate interstitialCustomEventWillLeaveApplication:self];
      }
      if ([self.delegate respondsToSelector:@selector(interstitialCustomEventDidReceiveTapEvent:)]) {
          [self.delegate interstitialCustomEventDidReceiveTapEvent:self];
      }
     } 
  
  - (void)dealloc {
      if (self.interstitialView != nil) {
          self.interstitialView.delegate = nil;
          self.interstitialView = nil;
      }
  }