Banners Ads II

出自TAMedia
跳至導覽 跳至搜尋

以下我們將展示更多的方法來控制Banner廣告的屬性。

廣告大小

TAMedia Ads支援下列大小的Banner廣告:

  • 640x100
  • 110x700
  • 468x60
  • 728x90
  • 1024x90
  • 640x640
  • 320x320
  • 300x250

可以在init的時候同時指定大小

    _adView = [[TWMTAMediaView alloc] initWithFrame:CGRectMake(0, 0, 320, 50) //在iPhone或iPod上需指定為320x50
                                             slotId:@"70mQH1335375881000QAr"
                                        developerID:@""
                                         gpsEnabled:YES
                                           testMode:NO];

GPS定位

    _adView = [[TWMTAMediaView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)
                                             slotId:@"70mQH1335375881000QAr"
                                        developerID:@""
                                         gpsEnabled:YES //YES表示SDK可以自動取得地理位置, NO則表示禁止SDK取得地址位置
                                           testMode:NO];

測試模式

    _adView = [[TWMTAMediaView alloc] initWithFrame:CGRectMake(0, 0, 320, 50)
                                             slotId:@"70mQH1335375881000QAr"
                                        developerID:@""
                                         gpsEnabled:YES
                                           testMode:NO];  //YES表示測試模式, 廣告點擊的相關資料不會被記錄, NO表示一般模式, 會記錄廣告點擊的相關資料

TWMTAMediaViewDelegate

你可以選擇透過實現全部或部分的TWMTAMediaViewDelegate方法來追踪Banner廣告的生命週期

@protocol TWMTAMediaViewDelegate <NSObject>
@optional

- (void)viewWillLoadAd:(TWMTAMediaView *)view;

- (void)viewDidLoadAd:(TWMTAMediaView *)view;

- (void)view:(TWMTAMediaView *)view didFailToReceiveAdWithError:(NSError *)error;

- (BOOL)viewActionShouldBegin:(TWMTAMediaView *)view willLeaveApplication:(BOOL)willLeave;

@end

你可以在UIViewController中實現TWMTAMediaViewDelegate方法

#import "TWMTAMediaViewController.h"

#import "TWMTAMediaView.h"

@interface TWMTAMediaViewController () <TWMTAMediaViewDelegate>
{
}
@end

並且透過TWMTAMediaView的setDelegate:方法來指定實現TWMTAMediaViewDelegate的對象

[_adView setDelegate:self];

請注意,如果你有實現TWMTAMediaViewDelegate,當TWMTAMediaView不再被使用時,必須將delegate設定為nil

- (void)dealloc
{
    _adView.delegate = nil;
    
    // Don't release the _adView if you are using ARC in your project
    [_adView release];
    
    _adView = nil;
}


- (void)viewWillLoadAd:(TWMTAMediaView *)view

TWMTAMediaView開始載入廣告前會先呼叫這個方法

- (void)viewWillLoadAd:(TWMTAMediaView *)view
{
    NSLog(@"%@ viewWillLoadAd", view);
}

- (void)viewDidLoadAd:(TWMTAMediaView *)view

你可以在確定廣告已經載入後才將TWMTAMediaView加入UI

- (void)viewDidLoadAd:(TWMTAMediaView *)view
{
    NSLog(@"%@ viewDidLoadAd", view);
    [self.view addSubview:_adView];
}

- (void)view:(TWMTAMediaView *)view didFailToReceiveAdWithError:(NSError *)error

你可以在這裡的得知載入廣告過程中發生的何異常

- (void)view:(TWMTAMediaView *)view didFailToReceiveAdWithError:(NSError *)error
{
    NSLog(@"%@ didFailToReceiveAdWithError:%@", view, error.description);
}

- (BOOL)viewActionShouldBegin:(TWMTAMediaView *)view willLeaveApplication:(BOOL)willLeave

當使用者點擊廣告後,TWMTAMediaView在開啟網頁或App Store前會先通知你

- (BOOL)viewActionShouldBegin:(TWMTAMediaView *)view willLeaveApplication:(BOOL)willLeave
{
    NSLog(@"%@ willLeaveApplication:%i", view, willLeave);
    return YES;
}