「Banner」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: 橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告 == Banners 大小種類 == {...)
 
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 10 次修訂)
行 1: 行 1:
橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告
橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告<br><br>


[[IOS SDK Developer Guide v2|回 iOS首頁]]<br>




== Banners 大小種類 ==
== Banners 大小種類 ==
           
{| class="wikitable"
{| class="wikitable"
|-
|-
行 23: 行 24:
TADBannerView 物件是 UIView 的 subclass, 呈現html5橫幅廣告
TADBannerView 物件是 UIView 的 subclass, 呈現html5橫幅廣告
加入橫幅廣告的簡單七步驟, 建議在viewController裡執行
加入橫幅廣告的簡單七步驟, 建議在viewController裡執行
:* 匯入 TADBannerView.h
:* 匯入 #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
:* 在 UIViewController裡宣告 TADBannerView 變數
:* 在 UIViewController裡宣告 TADBannerView 變數
:* 建立橫幅廣告
:* 建立橫幅廣告
行 31: 行 32:
:* 請求廣告
:* 請求廣告


 
'''// BannerViewController.h'''
==== BannerViewController.h ====
  '''// 匯入TADBannerView.h'''
  '''// 匯入 TAMedia SDK 定義'''
#import "TADBannerView.h"
<!-- #import "TADBannerView.h"-->
#import "TADBannerViewDelegate.h"
  #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
   
   
  @interface BannerViewController : UIViewController <TADBannerViewDelegate>{
  @interface BannerViewController : UIViewController <TADBannerViewDelegate>
     '''// 宣告 bannerView 為 instance variable'''
{
     '''// 以 instant variable 的方式, 宣告 bannerView 物件'''
     TADBannerView *bannerView;
     TADBannerView *bannerView;
  }
  }
  @end
  @end


==== BannerViewController.m ====
'''// BannerViewController.m'''
#import " BannerViewController.h"
   
   
  @implementation BannerViewController
  - (void)viewDidLoad
{
    [super viewDidLoad];
    '''// Do any additional setup after loading the view.'''
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TAMedia Banner";
   
    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:@"Banner Ad" forState:UIControlStateNormal];
    [fireButton1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [fireButton1 addTarget:self action:@selector(requestAd1) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fireButton1];
}
   
   
  - (void)viewDidLoad {
  - (void)requestAd1
[super viewDidLoad];
{
// Do any additional setup after loading the view, typically from a nib.
    TADRequest *request = [TADRequest request];
    '''// 顯示log'''   
'''// 建立新的橫幅在螢幕上方, Adsize 定義在TADAdsize.h中'''
    request.showLog = YES;
bannerView = [[TADBannerView alloc] initWithAdSize:kTADAdSizeBanner];
   
'''// 指定廣告Unit ID'''
    '''// Type: TADGender'''
bannerView.adUnitID = MY_BANNER_UNIT_ID;
    request.gender = [_GENDER_];
'''// 指定detegate'''
   
bannerView.delegate = self;
    '''// Set birthday'''
'''// 指定rootViewController'''
    [request setBirthdayWithYear:[_YEAR_] month:[_MONTH_] day:[_DAY_]];
bannerView.rootViewController = self;  
   
'''// 將廣告view 加入self.view並請求廣告'''
    '''// Set location'''
[self.view addSubview:_bannerView];  
    [request setLocationWithLatitude:[_LATITUDE_] longitude:[_LONGITUDE_] accuracy:[_ACCURACY_]];
[bannerView loadRequest: [TADRequest request]];
   
    '''// bannerView 物件初始化, 帶入自訂的origin'''
    if (!bannerView) {
        bannerView = [[TADBannerView alloc] initWithAdSize:kTADAdSizeBanner origin:CGPointMake(0, self.view.frame.size.height - 50)];
    }
   
    '''// 必須要設定delegate'''
    bannerView.delegate = self;
   
    '''//是否使用麥克風廣告 default為Yes/依需求自行修改'''
    bannerView.turnOnMicrophone = NO;
   
    '''// 設定 AD Unit ID'''
    bannerView.adUnitID = [_YOUR_AD_UNIT_ID_];
   
    '''// 設定 rootViewController'''
    bannerView.rootViewController = self;
   
    '''// 載入廣告'''
    [bannerView loadRequest:request];
  }
  }
@end


== 特別注意 ==
== 特別注意 ==
在 ViewController 的 view 即將消失前, 必須要將 bannerView 本身以及其 delegate 設定為 nil
'''// BannerViewController.m'''
 
  - (void)viewWillDisappear:(BOOL)animated {
  - (void)viewWillDisappear:(BOOL)animated {
  '''// view消失前, 必須要將bannerView物件及delegate設為nil'''
    '''// viewController 的 view 消失前, 必須將 bannerView 及其 delegate 設為 nil'''
  bannerView.delegate = nil;
    if (bannerView != nil) {
  bannerView = nil;
        bannerView.delegate = nil;
        bannerView = nil;
    }
  }
  }
若要將Banner放在螢幕下方, 建立時可定義origin
'''// 建立新的橫幅在螢幕下方, Adsize 定義在TADAdsize.h中'''
bannerView = [[TADBannerView alloc] initWithAdSize:kTADAdSizeBanner origin:CGPointMake(0, self.view.frame.size.height - 50)];




行 90: 行 117:
  @protocol TADBannerViewDelegate <NSObject>
  @protocol TADBannerViewDelegate <NSObject>
  @optional
  @optional
  // Ad Request Lifecycle Notifications
   
'''// Ad Request Lifecycle Notifications'''
'''// 廣告載入成功後被呼叫, 可以在這裡呈現廣告'''
  - (void)adViewDidReceiveAd:(TADBannerView *)view;
  - (void)adViewDidReceiveAd:(TADBannerView *)view;
'''// 廣告載入失敗後被呼叫'''
  - (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(TADRequestError *)error;
  - (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(TADRequestError *)error;
   
   
  // Click-Time Lifecycle Notifications
   
'''// Click-Time Lifecycle Notifications'''
'''// 廣告即將被呈現之前被呼叫'''
  - (void)adViewWillPresentScreen:(TADBannerView *)adView;
  - (void)adViewWillPresentScreen:(TADBannerView *)adView;
'''// 廣告即將被關閉之前被呼叫'''
  - (void)adViewWillDismissScreen:(TADBannerView *)adView;
  - (void)adViewWillDismissScreen:(TADBannerView *)adView;
'''// 廣告被關閉之後被呼叫'''
  - (void)adViewDidDismissScreen:(TADBannerView *)adView;
  - (void)adViewDidDismissScreen:(TADBannerView *)adView;
'''// 應用程式及將改在背景執行或中止運作前被呼叫'''
  - (void)adViewWillLeaveApplication:(TADBannerView *)adView;
  - (void)adViewWillLeaveApplication:(TADBannerView *)adView;
   
   
  @end
  @end
==== - (void)adViewDidReceiveAd:(TADBannerView *)view ====
廣告載入成功後被呼叫, 可以在這裡呈現廣告
==== - (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(TADRequestError *)error ====
廣告載入失敗後被呼叫
==== - (void)adViewWillPresentScreen:(TADBannerView *)adView ====
廣告即將被呈現之前被呼叫
==== - (void)adViewWillDismissScreen:(TADBannerView *)adView ====
廣告即將被關閉之前被呼叫
==== - (void)adViewDidDismissScreen:(TADBannerView *)adView ====
廣告被關閉之後被呼叫
==== - (void)adViewWillLeaveApplication:(TADBannerView *)adView ====
應用程式及將改在背景執行或中止運作前被呼叫








[[IOS SDK 2.0 Developer Guide|Back]]
[[IOS SDK 2.0 Developer Guide|回 iOS首頁]]

於 2018年6月21日 (四) 03:43 的最新修訂

橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告

回 iOS首頁


Banners 大小種類

BANNER IAB_MRECT IAB_BANNER IAB_LEADERBOARD
320x50 300x250 468x60 728x90


加入 TADBannerView

TADBannerView 物件是 UIView 的 subclass, 呈現html5橫幅廣告 加入橫幅廣告的簡單七步驟, 建議在viewController裡執行

  • 匯入 #import <TAMediaAdsFramework/TAMediaAdsFramework.h>
  • 在 UIViewController裡宣告 TADBannerView 變數
  • 建立橫幅廣告
  • 設定Unit ID
  • 設定 rootViewController
  • 將橫幅廣告加入UI
  • 請求廣告
// BannerViewController.h

// 匯入 TAMedia SDK 定義
 #import <TAMediaAdsFramework/TAMediaAdsFramework.h>

@interface BannerViewController : UIViewController <TADBannerViewDelegate>
{
    // 以 instant variable 的方式, 宣告 bannerView 物件
    TADBannerView *bannerView;
}

@end
// BannerViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TAMedia Banner";
    
    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:@"Banner 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];
    // 顯示log     
    request.showLog = YES;
    
    // Type: TADGender
    request.gender = [_GENDER_];
    
    // Set birthday
    [request setBirthdayWithYear:[_YEAR_] month:[_MONTH_] day:[_DAY_]];
    
    // Set location
    [request setLocationWithLatitude:[_LATITUDE_] longitude:[_LONGITUDE_] accuracy:[_ACCURACY_]];
    
    // bannerView 物件初始化, 帶入自訂的origin
    if (!bannerView) {
        bannerView = [[TADBannerView alloc] initWithAdSize:kTADAdSizeBanner origin:CGPointMake(0, self.view.frame.size.height - 50)];
    }
    
    // 必須要設定delegate
    bannerView.delegate = self;
   
    //是否使用麥克風廣告 default為Yes/依需求自行修改
    bannerView.turnOnMicrophone = NO;
    
    // 設定 AD Unit ID
    bannerView.adUnitID = [_YOUR_AD_UNIT_ID_];
    
    // 設定 rootViewController
    bannerView.rootViewController = self;
    
    // 載入廣告
    [bannerView loadRequest:request];
}

特別注意

// BannerViewController.m

- (void)viewWillDisappear:(BOOL)animated {
    // viewController 的 view 消失前, 必須將 bannerView 及其 delegate 設為 nil
    if (bannerView != nil) {
        bannerView.delegate = nil;
        bannerView = nil;
    }
}



TADBannerViewDelegate

@protocol TADBannerViewDelegate <NSObject>
@optional

// Ad Request Lifecycle Notifications

// 廣告載入成功後被呼叫, 可以在這裡呈現廣告
- (void)adViewDidReceiveAd:(TADBannerView *)view;

// 廣告載入失敗後被呼叫
- (void)adView:(TADBannerView *)view didFailToReceiveAdWithError:(TADRequestError *)error;


// Click-Time Lifecycle Notifications

// 廣告即將被呈現之前被呼叫
- (void)adViewWillPresentScreen:(TADBannerView *)adView;

// 廣告即將被關閉之前被呼叫
- (void)adViewWillDismissScreen:(TADBannerView *)adView;

// 廣告被關閉之後被呼叫
- (void)adViewDidDismissScreen:(TADBannerView *)adView;

// 應用程式及將改在背景執行或中止運作前被呼叫
- (void)adViewWillLeaveApplication:(TADBannerView *)adView;

@end



回 iOS首頁