「Video」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: 創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光 == 加入 TADVideoAdView == TADVideoAdVie...)
 
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 6 次修訂)
行 1: 行 1:
創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光
創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光<br><br>
 
[[IOS SDK Developer Guide v2|回 iOS首頁]]<br>




行 13: 行 15:
:*執行呼叫廣告
:*執行呼叫廣告


 
'''// VideoViewController.h'''
=== VideoViewController.h ===
 
  '''// 匯入 TAMedia SDK 定義'''
  '''// SDK 中匯入 TADVideoAdView 及 TADVideoAdViewDelegate 定義'''
  #import "TADVideoAdView.h"
  #import "TADVideoAdView.h"
#import "TADVideoAdViewDelegate.h"
   
   
  @interface VideoViewController : UIViewController <TADVideoAdViewDelegate>
  @interface VideoViewController : UIViewController <TADVideoAdViewDelegate>
  {
  {
    '''// 以instant variable的方式, 宣告 videoView 物件'''
    '''// 以 instant variable 的方式, 宣告 videoView 物件'''
     TADVideoAdView *videoView;
     TADVideoAdView *videoView;
  }
  }
行 28: 行 28:
  @end
  @end


 
'''// VideoViewController.m'''
=== VideoViewController.m ===
 
  @implementation VideoViewController
  @implementation VideoViewController
   
   
行 36: 行 35:
  {
  {
     [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 Video";
   
    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:@"Video 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_]];
      
      
     '''// videoView 物件初始化'''
     '''// videoView 物件初始化'''
     videoView = [[TADVideoAdView alloc] initWithVideoAd];
     if (videoView == nil) {
     '''// 設定 videoView Unit ID'''
        videoView = [[TADVideoAdView alloc] initWithVideoAd];
     videoView.adUnitID = MY_VIDEO_UNIT_ID;
    }
   
     '''// 設定 AD Unit ID'''
     videoView.adUnitID = [_YOUR_AD_UNIT_ID_];
   
     '''// 必須要設定 delegate'''
     '''// 必須要設定 delegate'''
     videoView.delegate = self;
     videoView.delegate = self;
     '''// 必須要設定 rootViewController'''
      
    videoView.rootViewController = self;
     '''// 載入廣告'''
     '''// 載入廣告'''
     [videoView loadRequest:[TADRequest request]];
     [videoView loadRequest:request];
  }
  }
   
   
行 58: 行 85:
在 ViewController 的 view 即將消失前, 必須要將 videoView 本身以及其 delegate 設定為 nil
在 ViewController 的 view 即將消失前, 必須要將 videoView 本身以及其 delegate 設定為 nil


=== ViewController Delegate Function ===
'''// VideoViewController.m'''
  - (void)viewWillDisappear:(BOOL)animated {
  - (void)viewWillDisappear:(BOOL)animated {
     '''// viewController 的 view 消失前, 必須將自己及 delegate 設為 nil'''
     '''// viewController 的 view 消失前, 必須將 videoView 及其 delegate 設為 nil'''
     videoView.delegate = nil;
     if (videoView != nil) {
    videoView = nil;
        videoView.delegate = nil;
        videoView = nil;
    }
  }
  }


行 68: 行 98:




== Delegate Functions ==
== TADVideoAdViewDelegate ==


  @protocol TADVideoAdViewDelegate <NSObject>
  @protocol TADVideoAdViewDelegate <NSObject>
@optional
   
   
  @optional
  '''// Ad Request Lifecycle Notifications'''
   
   
'''// 影音廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告'''
  - (void)adViewDidReceiveAd:(TADVideoAdView *)view;
  - (void)adViewDidReceiveAd:(TADVideoAdView *)view;
'''// 影音廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息'''
  - (void)adView:(TADVideoAdView *)view didFailToReceiveAdWithError:(TADRequestError *)error;
  - (void)adView:(TADVideoAdView *)view didFailToReceiveAdWithError:(TADRequestError *)error;
   
   
行 80: 行 114:




=== Ad Request Lifecycle Notifications ===
===== - (void)adViewDidReceiveAd:(TADVideoAdView *)view =====
:影音廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告


===== - (void)adView:(TADVideoAdView *)view didFailToReceiveAdWithError:(TADRequestError *)error =====
:影音廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息




[[IOS SDK 2.0 Developer Guide|Back]]
[[IOS SDK 2.0 Developer Guide|回 iOS首頁]]

於 2019年1月25日 (五) 09:26 的最新修訂

創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光

回 iOS首頁


加入 TADVideoAdView

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

  • 匯入 TADVideoAdView.h
  • 在 UIViewController 中宣告 TADVideoAdView 執行個體
  • 建立TADVideoAdView廣告
  • 設定廣告單元編號
  • 執行呼叫廣告
// VideoViewController.h

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

@interface VideoViewController : UIViewController <TADVideoAdViewDelegate>
{
    // 以 instant variable 的方式, 宣告 videoView 物件
    TADVideoAdView *videoView;
}

@end
// VideoViewController.m

@implementation VideoViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TAMedia Video";
    
    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:@"Video 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_]];
    
    // videoView 物件初始化
    if (videoView == nil) {
        videoView = [[TADVideoAdView alloc] initWithVideoAd];
    }
    
    // 設定 AD Unit ID
    videoView.adUnitID = [_YOUR_AD_UNIT_ID_];
    
    // 必須要設定 delegate
    videoView.delegate = self;
    
    // 載入廣告
    [videoView loadRequest:request];
}

@end



特別注意

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

// VideoViewController.m

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



TADVideoAdViewDelegate

@protocol TADVideoAdViewDelegate <NSObject>
@optional

// Ad Request Lifecycle Notifications

// 影音廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告
- (void)adViewDidReceiveAd:(TADVideoAdView *)view;

// 影音廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息
- (void)adView:(TADVideoAdView *)view didFailToReceiveAdWithError:(TADRequestError *)error;

@end



回 iOS首頁