「Video」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
(未顯示同一使用者於中間所作的 5 次修訂) | |||
行 1: | 行 1: | ||
創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光 | 創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光<br><br> | ||
[[IOS SDK Developer Guide v2|回 iOS首頁]]<br> | |||
行 13: | 行 15: | ||
:*執行呼叫廣告 | :*執行呼叫廣告 | ||
'''// VideoViewController.h''' | |||
'''// 匯入 TAMedia SDK 定義''' | |||
'''// | |||
#import "TADVideoAdView.h" | #import "TADVideoAdView.h" | ||
@interface VideoViewController : UIViewController <TADVideoAdViewDelegate> | @interface VideoViewController : UIViewController <TADVideoAdViewDelegate> | ||
{ | { | ||
'''// 以 instant variable 的方式, 宣告 videoView 物件''' | |||
TADVideoAdView *videoView; | TADVideoAdView *videoView; | ||
} | } | ||
行 28: | 行 28: | ||
@end | @end | ||
'''// 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 = [[TADVideoAdView alloc] initWithVideoAd]; | ||
videoView.adUnitID = | } | ||
'''// 設定 AD Unit ID''' | |||
videoView.adUnitID = [_YOUR_AD_UNIT_ID_]; | |||
'''// 必須要設定 delegate''' | '''// 必須要設定 delegate''' | ||
videoView.delegate = self; | videoView.delegate = self; | ||
'''// 載入廣告''' | '''// 載入廣告''' | ||
[videoView loadRequest: | [videoView loadRequest:request]; | ||
} | } | ||
行 56: | 行 85: | ||
在 ViewController 的 view 即將消失前, 必須要將 videoView 本身以及其 delegate 設定為 nil | 在 ViewController 的 view 即將消失前, 必須要將 videoView 本身以及其 delegate 設定為 nil | ||
'''// VideoViewController.m''' | |||
- (void)viewWillDisappear:(BOOL)animated { | - (void)viewWillDisappear:(BOOL)animated { | ||
'''// viewController 的 view 消失前, | '''// viewController 的 view 消失前, 必須將 videoView 及其 delegate 設為 nil''' | ||
videoView.delegate = nil; | if (videoView != nil) { | ||
videoView.delegate = nil; | |||
videoView = nil; | |||
} | |||
} | } | ||
行 66: | 行 98: | ||
== | == TADVideoAdViewDelegate == | ||
@protocol TADVideoAdViewDelegate <NSObject> | @protocol TADVideoAdViewDelegate <NSObject> | ||
@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; | ||
行 78: | 行 114: | ||
[[IOS SDK 2.0 Developer Guide| | [[IOS SDK 2.0 Developer Guide|回 iOS首頁]] |
於 2019年1月25日 (五) 09:26 的最新修訂
創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光
加入 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