Interstitial Ads
於 2014年1月28日 (二) 03:20 由 imported>Wikiuser 所做的修訂 (新頁面: Interstitial廣告可以在app啟動, 視頻載入期間或遊戲暫停的時候,呈現內容豐富的HTML5網頁或Web App。。<br> 以下將告訴您如何讓您的app顯示Inters...)
Interstitial廣告可以在app啟動, 視頻載入期間或遊戲暫停的時候,呈現內容豐富的HTML5網頁或Web App。。
以下將告訴您如何讓您的app顯示Interstitial廣告。
增加TWMTAMediaInterstitialView
TWMTAMediaInterstitialView是NSObject的子類別,透過以下步驟可以很簡單的將Interstitial廣告加入App中:
- Import TWMTAMediaInterstitialView.h
- 宣告一個TWMTAMediaInterstitialView的實體在顯示Interstitial廣告的UIViewController
- alloc & init TWMTAMediaInterstitialView
- 載入廣告
#import "TWMTAMediaViewController.h" #import "TWMTAMediaView.h" #import "TWMTAMediaInterstitialView.h" @interface TWMTAMediaViewController () <TWMTAMediaViewDelegate, TWMTAMediaInterstitialViewDelegate> { TWMTAMediaView *_adView; TWMTAMediaInterstitialView *_interstitialView; } @end @implementation TWMTAMediaViewController //@synthesize _adView; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. CGRect frame = CGRectMake(0, 0, [UIScreen mainScreen].applicationFrame.size.width, [UIScreen mainScreen].applicationFrame.size.height); _interstitialView = [[TWMTAMediaInterstitialView alloc] initWithFrame:frame slotId:@"h0Lz1374718054864uDt" developerID:@"" gpsEnabled:YES testMode:NO]; [_interstitialView receiveAd]; } @end
當Interstitial廣告載入完成且要呈現時才需要呼叫showAd:方法
[_interstitialView showAd:self.view];
TWMTAMediaInterstitialViewDelegate
你可以選擇透過實現全部或部分的TWMTAMediaInterstitialViewDelegate方法來追踪Interstitial廣告的生命週期
@protocol TWMTAMediaInterstitialViewDelegate <NSObject> @optional - (void)interstitialViewWillLoadAd:(TWMTAMediaInterstitialView *)view; - (void)interstitialViewDidLoadAd:(TWMTAMediaInterstitialView *)view; - (void)interstitialView:(TWMTAMediaInterstitialView *)view didFailToReceiveAdWithError:(NSError *)error; - (BOOL)interstitialViewActionShouldBegin:(TWMTAMediaInterstitialView *)view willLeaveApplication:(BOOL)willLeave; - (void)interstitialViewWillDisappear:(TWMTAMediaInterstitialView *)view; - (void)interstitialViewDidDisappear:(TWMTAMediaInterstitialView *)view; @end
你可以在UIViewController中實現TWMTAMediaInterstitialViewDelegate方法
#import "TWMTAMediaViewController.h" #import "TWMTAMediaInterstitialView.h" @interface TWMTAMediaViewController () <TWMTAMediaInterstitialViewDelegate> { } @end
並且透過TWMTAMediaInterstitialView的setDelegate:方法來指定實現TWMTAMediaInterstitialViewDelegate的對象
[_interstitialView setDelegate:self];
請注意,如果你有實現TWMTAMediaInterstitialViewDelegate,當TWMTAMediaInterstitialView不再被使用時,必須將delegate設定為nil
- (void)dealloc { _interstitialView.delegate = nil; // Don't release the _adView if you are using ARC in your project [_interstitialView release]; _interstitialView = nil; }
- (void)interstitialViewWillLoadAd:(TWMTAMediaInterstitialView *)view
TWMTAMediaInterstitialView開始載入廣告前會先呼叫這個方法
- (void)interstitialViewWillLoadAd:(TWMTAMediaInterstitialView *)view { NSLog(@"%@ interstitialViewWillLoadAd", view); }
- (void)interstitialViewDidLoadAd:(TWMTAMediaInterstitialView *)view
你可以在確定廣告已經載入後才將TWMTAMediaInterstitialView加入UI
- (void)interstitialViewDidLoadAd:(TWMTAMediaInterstitialView *)view { NSLog(@"%@ interstitialViewDidLoadAd", view); [_interstitialView showAd:self.view]; }
- (void)interstitialView:(TWMTAMediaInterstitialView *)view didFailToReceiveAdWithError:(NSError *)error
你可以在這裡的得知載入廣告過程中發生的何異常
- (void)interstitialView:(TWMTAMediaInterstitialView *)view didFailToReceiveAdWithError:(NSError *)error { NSLog(@"%@ interstitialViewdidFailToReceiveAdWithError:%@", view, error.description); }
- (BOOL)interstitialViewActionShouldBegin:(TWMTAMediaInterstitialView *)view willLeaveApplication:(BOOL)willLeave
當使用者點擊廣告後,TWMTAMediaView在開啟網頁或App Store前會先通知你
- (BOOL)interstitialViewActionShouldBegin:(TWMTAMediaInterstitialView *)view willLeaveApplication:(BOOL)willLeave { NSLog(@"%@ interstitialViewwillLeaveApplication:%i", view, willLeave); return YES; }