「Interstitial」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
行 13: | 行 13: | ||
:*設定廣告單元編號 | :*設定廣告單元編號 | ||
'''// InterstitialViewController.h''' | |||
'''// 匯入 TAMedia SDK 定義''' | '''// 匯入 TAMedia SDK 定義''' | ||
#import "TADInterstitial.h" | #import "TADInterstitial.h" | ||
@interface InterstitialViewController : UIViewController <TADInterstitialDelegate> | @interface InterstitialViewController : UIViewController <TADInterstitialDelegate> | ||
行 28: | 行 26: | ||
@end | @end | ||
'''// InterstitialViewController.m''' | |||
#import "InterstitialViewController.h" | #import "InterstitialViewController.h" | ||
行 86: | 行 83: | ||
在 ViewController 的 view 即將消失前, 或是 interstitialView 消失前, 必須要將 interstitialView 本身以及其 delegate 設定為 nil | 在 ViewController 的 view 即將消失前, 或是 interstitialView 消失前, 必須要將 interstitialView 本身以及其 delegate 設定為 nil | ||
'''// InterstitialViewController.m''' | |||
'''// ViewController Delegate Function''' | |||
- (void)viewWillDisappear:(BOOL)animated { | - (void)viewWillDisappear:(BOOL)animated { | ||
'''// viewController 的 view 消失前, 必須將 interstitialView 及其 delegate 設為 nil''' | '''// viewController 的 view 消失前, 必須將 interstitialView 及其 delegate 設為 nil''' | ||
行 95: | 行 93: | ||
} | } | ||
} | } | ||
'''// TADInterstitial Delegate Function''' | |||
- (void)interstitialDidDismissScreen:(TADInterstitial *)ad{ | - (void)interstitialDidDismissScreen:(TADInterstitial *)ad{ | ||
'''// interstitialView 關閉前, 必須將 interstitialView 及其 delegate 設為 nil''' | '''// interstitialView 關閉前, 必須將 interstitialView 及其 delegate 設為 nil''' | ||
行 109: | 行 106: | ||
== | == TADInterstitialDelegate == | ||
@protocol TADInterstitialDelegate <NSObject> | @protocol TADInterstitialDelegate <NSObject> | ||
@optional | @optional | ||
'''// Ad Request Lifecycle Notifications''' | |||
'''// Interstitial廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告''' | |||
- (void)interstitialDidReceiveAd:(TADInterstitial *)ad; | - (void)interstitialDidReceiveAd:(TADInterstitial *)ad; | ||
'''// Interstitial廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息''' | |||
- (void)interstitial:(TADInterstitial *)ad didFailToReceiveAdWithError:(TADRequestError *)error; | - (void)interstitial:(TADInterstitial *)ad didFailToReceiveAdWithError:(TADRequestError *)error; | ||
'''// Display-Time Lifecycle Notifications''' | |||
'''// Interstitial廣告呈現之前呼叫, 注意使用者可能會在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式, 可以在這function中處理該暫停之項目''' | |||
- (void)interstitialWillPresentScreen:(TADInterstitial *)ad; | - (void)interstitialWillPresentScreen:(TADInterstitial *)ad; | ||
'''// Interstitial廣告關閉, 在螢幕上消失之前呼叫, 再次提醒在Interstitail消失前, 必須將Interstitial及delegate設為nil (可以在這個function中執行)''' | |||
- (void)interstitialWillDismissScreen:(TADInterstitial *)ad; | - (void)interstitialWillDismissScreen:(TADInterstitial *)ad; | ||
'''// Interstitial廣告關閉, 在螢幕上消失之後呼叫''' | |||
- (void)interstitialDidDismissScreen:(TADInterstitial *)ad; | - (void)interstitialDidDismissScreen:(TADInterstitial *)ad; | ||
'''// 使用者在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式之前呼叫''' | |||
- (void)interstitialWillLeaveApplication:(TADInterstitial *)ad; | - (void)interstitialWillLeaveApplication:(TADInterstitial *)ad; | ||
@end | @end | ||
[[IOS SDK 2.0 Developer Guide|Back]] | [[IOS SDK 2.0 Developer Guide|Back]] |
於 2014年7月24日 (四) 09:26 的修訂
Interstitial廣告可以在app啟動, 視頻載入期間或遊戲暫停的時候,呈現內容豐富的HTML5網頁或Web App。。
以下將告訴您如何讓您的app顯示Interstitial廣告。
加入 TADInterstitial
TADInterstitial 的用法與 TADBannerView 相似,簡單的步驟即可加入TADInterstitial 建議在 UIViewController 中執行以下步驟:
- 匯入 TADInterstitial.h
- 在 UIViewController 中宣告 TADInterstitial 執行個體
- 建立插頁式廣告
- 設定廣告單元編號
// InterstitialViewController.h // 匯入 TAMedia SDK 定義 #import "TADInterstitial.h" @interface InterstitialViewController : UIViewController <TADInterstitialDelegate> { // 以 instant variable 的方式, 宣告 interstitialView 物件 TADInterstitial *interstitialView; } @end
// InterstitialViewController.m #import "InterstitialViewController.h" @implementation InterstitialViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor whiteColor]; self.title = @"TAMedia Interstitial"; 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:@"Interstitial 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_]]; // interstitialView 物件初始化 if (interstitialView == nil) { interstitialView = [[TADInterstitial alloc] init]; } // 必須要設定delegate interstitialView.delegate = self; // 設定 AD Unit ID interstitialView.adUnitID = [_YOUR_AD_UNIT_AD_]; // 載入廣告 [interstitialView loadRequest:request]; } @end
特別注意
在 ViewController 的 view 即將消失前, 或是 interstitialView 消失前, 必須要將 interstitialView 本身以及其 delegate 設定為 nil
// InterstitialViewController.m // ViewController Delegate Function - (void)viewWillDisappear:(BOOL)animated { // viewController 的 view 消失前, 必須將 interstitialView 及其 delegate 設為 nil if (interstitialView != nil) { interstitialView.delegate = nil; interstitialView = nil; } } // TADInterstitial Delegate Function - (void)interstitialDidDismissScreen:(TADInterstitial *)ad{ // interstitialView 關閉前, 必須將 interstitialView 及其 delegate 設為 nil if (interstitialView != nil) { interstitialView.delegate = nil; interstitialView = nil; } }
TADInterstitialDelegate
@protocol TADInterstitialDelegate <NSObject> @optional // Ad Request Lifecycle Notifications // Interstitial廣告成功載入後呼叫, 可以在此時間點及之後顯示呈現廣告 - (void)interstitialDidReceiveAd:(TADInterstitial *)ad; // Interstitial廣告載入失敗時呼叫, 處理錯誤 或 顯示錯誤訊息 - (void)interstitial:(TADInterstitial *)ad didFailToReceiveAdWithError:(TADRequestError *)error; // Display-Time Lifecycle Notifications // Interstitial廣告呈現之前呼叫, 注意使用者可能會在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式, 可以在這function中處理該暫停之項目 - (void)interstitialWillPresentScreen:(TADInterstitial *)ad; // Interstitial廣告關閉, 在螢幕上消失之前呼叫, 再次提醒在Interstitail消失前, 必須將Interstitial及delegate設為nil (可以在這個function中執行) - (void)interstitialWillDismissScreen:(TADInterstitial *)ad; // Interstitial廣告關閉, 在螢幕上消失之後呼叫 - (void)interstitialDidDismissScreen:(TADInterstitial *)ad; // 使用者在廣告內按下連結(網頁, AppStore, ...)而因此離開應用程式之前呼叫 - (void)interstitialWillLeaveApplication:(TADInterstitial *)ad; @end