TAMedia Wiki

NativeAd

回iOS首頁
請依照 開始使用Getting Started 章節進行SDK 的安裝 並以下述的方式啟動原生性廣告服務

// NADViewController.h

// 匯入 TAMedia SDK 定義

 #import <TAMediaAdsFramework/TAMediaAdsFramework.h>

@interface NADViewController: UIViewController <TADNativeAdDelegate>

{

// 以 instant variable 的方式, 宣告 TADNatvieAd 物件

TADNativeAd * nativeAd;

}

@end
// NADViewController.m

- (void)viewDidLoad

{

[super viewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColor whiteColor];

self.title = @"TAMedia NAD";

UIButton *fireButton1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];

fireButton1.frame = CGRectMake(10, 120, 200, 40);

fireButton1.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];

[fireButton1 setTitle:@"Native Ad" forState:UIControlStateNormal];

[fireButton1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

[fireButton1 addTarget:self action:@selector(requestAd1) forControlEvents:UIControlEventTouchUpInside];

[self.view addSubview:fireButton1];

}

請求廣告

- (void)requestAd1

{

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_]];

// NAD 物件初始化, 帶入自訂的origin

if (!nativeAd) {

nativeAd = [[TADNativeAd alloc] initWithAdUnitId: [_YOUR_AD_UNIT_ID_]];

}

// 必須要設定delegate

nativeAd.delegate = self;

// 載入廣告

[nativeAd loadRequest:request];

}

收到廣告廣告,開發商可依照APP最恰當的方式來將取得的廣告內容佈局在APP的呈現上,點擊時可使用下敘兩種方式開啟廣告
1.使用[nativeAd handleClick];
2.使用[UIApplication sharedApplication] openURL:"開啟dictionary中的nurl"]

- (void)nativeAdDidReceiveAd:(TADNativeAd *)ad {

// 表示本次請求收到廣告, 藉由 getNativeAdContent 取得包含回覆內容的 NSDictionary

NSDictionary *dicNad = [nativeAd getNativeAdContent];

/*利用拿到的Dictionary依所需要的方式呈現廣告

  當user點擊廣告時提供兩種方式開啟廣告

  1.使用[nativeAd handleClick];

  2.使用[UIApplication sharedApplication] openURL:"開啟dictionary中的nurl"]

*/

}

原生性廣告內容 前述之getNativeAdContent 所取回的NSDictionary 詳細內容如後

{

"LONGSUBJECT": "長標題 long subject ,※預設值為空字串",

"SHORTSUBJECT": "短標題 short subject ,※預設值為空字串",

"BODY": "內文 body ,※預設值為空字串",

"ICONSQUARE": "小圖示 方 icon square ,※預設值為空字串",

"ICONRECTANGLE": "小圖示 長 icon rectangle,※預設值為空字串",

"VIDEO": "影片 video,※預設值為空字串",

"IMAGE1280X720": "大圖 1280x720,※預設值為空字串",

"IMAGE960X640": "大圖 960x640,※預設值為空字串",

"IMAGE1200X627": "大圖 1200x627,※預設值為空字串"

"nurl": "廣告檔次Target URL", //當廣告發生點擊時回報的url

}

特別注意, 在 ViewController 的 view 即將消失前, 必須要將 nativeAd 本身以及其 delegate 設定為 nil

// NADViewController.m

- (void)viewWillDisappear:(BOOL)animated {

// viewController 的 view 消失前, 必須將 nativeAd 及其 delegate 設為 nil

 if (nativeAd!= nil) {

 nativeAd.delegate = nil;

 nativeAd = nil;

 }

}

TADNativeAdDelegate

@protocol TADNativeAdDelegate <NSObject>

@optional

//廣告載入成功後被呼叫, 在這裏利用 [nativeAd getNativeAdContent] 取得回覆的 dictionary

- (void)nativeAdDidReceiveAd:(TADNativeAd *)ad;

//廣告載入失敗後被呼叫

- (void)nativeAd:(TADNativeAd *)ad didFailToReceiveAdWithError:(TADRequestError *)error;

@end

※重要, 下表所描述的廣告素材有可能因廣告主未提供素材, 而以空字串提供, 使用上請特別留意

素材 \ 版位

限制條件

條列式

圖片式 (橫 16:9)

圖片式 (橫 3:2)

小圖式

影音式

長標題
(LONGSUBJECT)

25字內

V

V

V

V

短標題
(SHORTSUBJECT)

10字內

V

V

V

V

內文
(BODY)

70字內

V

V

V

V

小圖 (方)
(ICONSQUARE)

120x120
jpg/png

V

V

V

小圖 (長)
(ICONRECTANGLE)

96x64
jpg/png

V

V

影片
(VIDEO)

96x64
MP4, 10mb

V

大圖 (橫 16:9)
(IMAGE1280X720)

1280x720
jpg/png

V

大圖 (橫 3:2)
(IMAGE960X640)

960x640
jpg/png

V

V

大圖
(IMAGE1200X627)

1200x627
jpg/png

V

V

V

V

V