「Interstitial」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: Interstitial廣告可以在app啟動, 視頻載入期間或遊戲暫停的時候,呈現內容豐富的HTML5網頁或Web App。。<br> 以下將告訴您如何讓您的app顯示Inters...)
 
imported>Wikiuser
行 16: 行 16:
=== InterstitialViewController.h ===
=== InterstitialViewController.h ===


  '''// SDK 中匯入 TADInterstitial 及 TADInterstitialDelegate 定義'''
  '''// 匯入 TAMedia SDK 定義'''
  #import "TADInterstitial.h"
  #import "TADInterstitial.h"
  #import "TADInterstitialDelegate.h"
  #import "TADInterstitialDelegate.h"
行 22: 行 22:
  @interface InterstitialViewController : UIViewController <TADInterstitialDelegate>
  @interface InterstitialViewController : UIViewController <TADInterstitialDelegate>
  {
  {
    '''// 以instant variable的方式, 宣告 Interstitial 物件'''
    '''// 以 instant variable 的方式, 宣告 interstitialView 物件'''
    TADInterstitial *interstitialView;
    TADInterstitial *interstitialView;
  }
  }
   
   
行 38: 行 38:
  {
  {
     [super viewDidLoad];
     [super viewDidLoad];
     // Do any additional setup after loading the view.
     '''// Do any additional setup after loading the view.'''
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TAMedia Interstitial";
   
    UIButton *fireButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    fireButton.frame = CGRectMake(10, 120, 200, 40);
    fireButton.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];
    [fireButton setTitle:@"Interstitial Ad" forState:UIControlStateNormal];
    [fireButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [fireButton addTarget:self action:@selector(requestAd) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fireButton];
}
- (void)requestAd
{
    TADRequest *request = [TADRequest request];
   
    '''// Type: TADGender'''
    request.gender = [_GENDER_];
   
    '''// Set birthday'''
    [request setBirthdayWithYear:[_YEAR_] month:[_MONTH_] day:[_DAY_]];
   
    '''// Set location'''
    [request setLocationWithLatitude:[_LATITUDE_] longitude:[_LONGITUDE_] accuracy:[_ACCURACY_]];
   
   
     '''// interstitial物件初始化'''
     '''// interstitialView 物件初始化'''
     interstitialView = [[TADInterstitial alloc] init];
     if (interstitialView == nil) {
        interstitialView = [[TADInterstitial alloc] init];
    }
   
     '''// 必須要設定delegate'''
     '''// 必須要設定delegate'''
     interstitialView.delegate = self;
     interstitialView.delegate = self;
     '''// 設定Interstitial Unit ID'''
   
     interstitialView.adUnitID = My_INTERSTITIAL_UNIT_ID;
     '''// 設定 AD Unit ID'''
     interstitialView.adUnitID = [_YOUR_AD_UNIT_AD_];
   
     '''// 載入廣告'''
     '''// 載入廣告'''
     [interstitialView loadRequest:[TADRequest request]];
     [interstitialView loadRequest:request];
  }
  }
   
   
行 60: 行 89:
=== ViewController Delegate Function ===
=== ViewController Delegate Function ===
  - (void)viewWillDisappear:(BOOL)animated {
  - (void)viewWillDisappear:(BOOL)animated {
     '''// viewController 的 view 消失前, 必須將自己及 delegate 設為 nil'''
     '''// viewController 的 view 消失前, 必須將 interstitialView 及其 delegate 設為 nil'''
     interstitialView.delegate = nil;
     if (interstitialView != nil) {
    interstitialView = nil;
        interstitialView.delegate = nil;
        interstitialView = nil;
    }
  }
  }




=== TADInterstitial Delegate Function ===
=== TADInterstitial Delegate Function ===
  - (void)interstitialDidDismissScreen:(TADInterstitial *)ad
  - (void)interstitialDidDismissScreen:(TADInterstitial *)ad{
{
     '''// interstitialView 關閉前, 必須將 interstitialView 及其 delegate 設為 nil'''
     '''// interstitialView 關閉前, 必須將自己及 delegate 設為 nil'''
     if (interstitialView != nil) {
     interstitialView.delegate = nil;
        interstitialView.delegate = nil;
    interstitialView = nil;
        interstitialView = nil;
    }
  }
  }



於 2014年7月10日 (四) 10:42 的修訂

Interstitial廣告可以在app啟動, 視頻載入期間或遊戲暫停的時候,呈現內容豐富的HTML5網頁或Web App。。
以下將告訴您如何讓您的app顯示Interstitial廣告。


加入 TADInterstitial

TADInterstitial 的用法與 TADBannerView 相似,簡單的步驟即可加入TADInterstitial 建議在 UIViewController 中執行以下步驟:

  • 匯入 TADInterstitial.h
  • 在 UIViewController 中宣告 TADInterstitial 執行個體
  • 建立插頁式廣告
  • 設定廣告單元編號


InterstitialViewController.h

// 匯入 TAMedia SDK 定義
#import "TADInterstitial.h"
#import "TADInterstitialDelegate.h"

@interface InterstitialViewController : UIViewController <TADInterstitialDelegate>
{
    // 以 instant variable 的方式, 宣告 interstitialView 物件
    TADInterstitial *interstitialView;
}

@end


InterstitialViewController.m

#import "InterstitialViewController.h"

@implementation InterstitialViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TAMedia Interstitial";
    
    UIButton *fireButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    fireButton.frame = CGRectMake(10, 120, 200, 40);
    fireButton.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];
    [fireButton setTitle:@"Interstitial Ad" forState:UIControlStateNormal];
    [fireButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [fireButton addTarget:self action:@selector(requestAd) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fireButton];
}

- (void)requestAd
{
    TADRequest *request = [TADRequest request];
    
    // Type: TADGender
    request.gender = [_GENDER_];
    
    // Set birthday
    [request setBirthdayWithYear:[_YEAR_] month:[_MONTH_] day:[_DAY_]];
    
    // Set location
    [request setLocationWithLatitude:[_LATITUDE_] longitude:[_LONGITUDE_] accuracy:[_ACCURACY_]];

    // interstitialView 物件初始化
    if (interstitialView == nil) {
        interstitialView = [[TADInterstitial alloc] init];
    }
    
    // 必須要設定delegate
    interstitialView.delegate = self;
    
    // 設定 AD Unit ID
    interstitialView.adUnitID = [_YOUR_AD_UNIT_AD_];
    
    // 載入廣告
    [interstitialView loadRequest:request];
}

@end


特別注意

在 ViewController 的 view 即將消失前, 或是 interstitialView 消失前, 必須要將 interstitialView 本身以及其 delegate 設定為 nil


ViewController Delegate Function

- (void)viewWillDisappear:(BOOL)animated {
    // viewController 的 view 消失前, 必須將 interstitialView 及其 delegate 設為 nil
    if (interstitialView != nil) {
        interstitialView.delegate = nil;
        interstitialView = nil;
    }
}


TADInterstitial Delegate Function

- (void)interstitialDidDismissScreen:(TADInterstitial *)ad{
    // interstitialView 關閉前, 必須將 interstitialView 及其 delegate 設為 nil
    if (interstitialView != nil) {
        interstitialView.delegate = nil;
        interstitialView = nil;
    }
}



Delegate Functions

@protocol TADInterstitialDelegate <NSObject>
@optional
- (void)interstitialDidReceiveAd:(TADInterstitial *)ad;
- (void)interstitial:(TADInterstitial *)ad didFailToReceiveAdWithError:(TADRequestError *)error;

- (void)interstitialWillPresentScreen:(TADInterstitial *)ad;
- (void)interstitialWillDismissScreen:(TADInterstitial *)ad;
- (void)interstitialDidDismissScreen:(TADInterstitial *)ad;
- (void)interstitialWillLeaveApplication:(TADInterstitial *)ad;
@end


Ad Request Lifecycle Notifications

- (void)interstitialDidReceiveAd:(TADInterstitial *)ad
Interstitial廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告
- (void)interstitial:(TADInterstitial *)ad didFailToReceiveAdWithError:(TADRequestError *)error
Interstitial廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息


Display-Time Lifecycle Notifications

- (void)interstitialWillPresentScreen:(TADInterstitial *)ad
Interstitial廣告呈現之前呼叫, 注意使用者可能會在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式, 可以在這function中處理該暫停之項目。
- (void)interstitialWillDismissScreen:(TADInterstitial *)ad
Interstitial廣告關閉, 在螢幕上消失之前呼叫, 再次提醒在Interstitail消失前, 必須將Interstitial及delegate設為nil (可以在這個function中執行)
- (void)interstitialDidDismissScreen:(TADInterstitial *)ad
Interstitial廣告關閉, 在螢幕上消失之後呼叫
- (void)interstitialWillLeaveApplication:(TADInterstitial *)ad
使用者在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式之前呼叫


Back