「Video」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
imported>Wikiuser
行 16: 行 16:
=== VideoViewController.h ===
=== VideoViewController.h ===


  '''// SDK 中匯入 TADVideoAdView 及 TADVideoAdViewDelegate 定義'''
  '''// 匯入 TAMedia SDK 定義'''
  #import "TADVideoAdView.h"
  #import "TADVideoAdView.h"
  #import "TADVideoAdViewDelegate.h"
  #import "TADVideoAdViewDelegate.h"
行 22: 行 22:
  @interface VideoViewController : UIViewController <TADVideoAdViewDelegate>
  @interface VideoViewController : UIViewController <TADVideoAdViewDelegate>
  {
  {
    '''// 以instant variable的方式, 宣告 videoView 物件'''
    '''// 以 instant variable 的方式, 宣告 videoView 物件'''
     TADVideoAdView *videoView;
     TADVideoAdView *videoView;
  }
  }
行 36: 行 36:
  {
  {
     [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;
   
     '''// 載入廣告'''
     '''// 載入廣告'''
     [videoView loadRequest:[TADRequest request]];
     [videoView loadRequest:request];
  }
  }
   
   
行 58: 行 88:
=== ViewController Delegate Function ===
=== ViewController Delegate Function ===
  - (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;
    }
  }
  }



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

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


加入 TADVideoAdView

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

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


VideoViewController.h

// 匯入 TAMedia SDK 定義
#import "TADVideoAdView.h"
#import "TADVideoAdViewDelegate.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

ViewController Delegate Function

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



Delegate Functions

@protocol TADVideoAdViewDelegate <NSObject>

@optional

- (void)adViewDidReceiveAd:(TADVideoAdView *)view;
- (void)adView:(TADVideoAdView *)view didFailToReceiveAdWithError:(TADRequestError *)error;

@end


Ad Request Lifecycle Notifications

- (void)adViewDidReceiveAd:(TADVideoAdView *)view
影音廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告
- (void)adView:(TADVideoAdView *)view didFailToReceiveAdWithError:(TADRequestError *)error
影音廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息


Back