「Video」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
| 行 84: | 行 84: | ||
'''// VideoViewController.m''' | '''// VideoViewController.m''' | ||
- (void)viewWillDisappear:(BOOL)animated { | - (void)viewWillDisappear:(BOOL)animated { | ||
'''// viewController 的 view 消失前, 必須將 videoView 及其 delegate 設為 nil''' | '''// viewController 的 view 消失前, 必須將 videoView 及其 delegate 設為 nil''' | ||
於 2014年7月24日 (四) 09:16 的修訂
創新的影音廣告讓你可以以影音的方式作最好的呈現, 一出現即吸引用戶的注意, 達到更深刻更有效的曝光
加入 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