「Expandable」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
(新頁面: 擴張式廣告結合了橫幅及插頁式廣告, 讓橫幅廣告被點擊後先不會因打開瀏覽器app而離開廣告所在的app, 讓使用者可以在同一個app裡全版面的...)
 
imported>Wikiuser
 
(未顯示同一使用者於中間所作的 16 次修訂)
行 1: 行 1:
擴張式廣告結合了橫幅及插頁式廣告, 讓橫幅廣告被點擊後先不會因打開瀏覽器app而離開廣告所在的app, 讓使用者可以在同一個app裡全版面的豐富體驗
擴張式廣告結合了橫幅及插頁式廣告, 讓橫幅廣告被點擊後先不會因打開瀏覽器app而離開廣告所在的app, 讓使用者可以在同一個app裡全版面的豐富體驗<br><br>


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




== 加入 ExpandableView ==
== 加入 ExpandableView ==
Expandable廣告使用 '''TADBannerView class''' 來實現擴張的行為
Expandable廣告使用 '''TADBannerView class''' 來實現擴張的行為
TADBannerView 的加入方法來加入
加入方法與 TADBannerView 相同


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


==== ExpandableViewController.m ====
'''// ExpandableViewController.m'''
#import " ExpandableViewController.h"
   
   
  @implementation BannerViewController
  - (void)viewDidLoad
{
    [super viewDidLoad];
    '''// Do any additional setup after loading the view.'''
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TAMedia Expandable";
   
   
- (void)viewDidLoad {
    UIButton *fireButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[super viewDidLoad];
    fireButton.frame = CGRectMake(10, 120, 200, 40);
  // Do any additional setup after loading the view, typically from a nib.
    fireButton.backgroundColor = [UIColor colorWithRed:239/255.0 green:239/255.0 blue:239/255.0 alpha:1.0];
    [fireButton setTitle:@"Expandable Ad" forState:UIControlStateNormal];
    [fireButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [fireButton addTarget:self action:@selector(requestAd) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:fireButton];
  }
   
   
  '''// 建立新的橫幅在螢幕上方, Adsize 定義在TADAdsize.h中'''
  - (void)requestAd
bannerView = [[TADBannerView alloc] initWithAdSize:kTADAdSizeBanner];
{
'''// 指定廣告Unit ID'''
    TADRequest *request = [TADRequest request];
bannerView.adUnitID = MY_BANNER_UNIT_ID;
   
'''// 指定detegate'''
    '''// Type: TADGender'''
bannerView.delegate = self;
    request.gender = [_GENDER_];
'''// 指定rootViewController'''
   
bannerView.rootViewController = self;  
    '''// Set birthday'''
'''// 將廣告view 加入self.view並請求廣告'''
    [request setBirthdayWithYear:[_YEAR_] month:[_MONTH_] day:[_DAY_]];
[self.view addSubview:_bannerView];
   
[bannerView loadRequest: [TADRequest request]];
    '''// 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;
   
    '''// 設定 AD Unit ID'''
    bannerView.adUnitID = [_YOUR_AD_UNIT_ID_];
   
    '''// 設定 rootViewController'''
    bannerView.rootViewController = self;
   
    '''// 載入廣告'''
    [bannerView loadRequest:request];
  }
  }
@end




行 48: 行 76:
在 ViewController 的 view 即將消失前, 必須要將 bannerView 本身以及其 delegate 設定為 nil
在 ViewController 的 view 即將消失前, 必須要將 bannerView 本身以及其 delegate 設定為 nil


'''// ExpandableViewController.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;
    }
  }
  }
若要將Expandable的Banner放在螢幕下方, 建立時可定義origin
'''// 建立新的橫幅在螢幕下方, Adsize 定義在TADAdsize.h中'''
bannerView = [[TADBannerView alloc] initWithAdSize:kTADAdSizeBanner origin:CGPointMake(0, self.view.frame.size.height - 50)];




行 65: 行 92:
  @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首頁]]

於 2019年1月25日 (五) 09:27 的最新修訂

擴張式廣告結合了橫幅及插頁式廣告, 讓橫幅廣告被點擊後先不會因打開瀏覽器app而離開廣告所在的app, 讓使用者可以在同一個app裡全版面的豐富體驗

回 iOS首頁


加入 ExpandableView

Expandable廣告使用 TADBannerView class 來實現擴張的行為 加入方法與 TADBannerView 相同

// ExpandableViewController.h

// 匯入 TAMedia SDK 定義
#import "TADBannerView.h"

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

@end
// ExpandableViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"TAMedia Expandable";

    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:@"Expandable 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_]];
    
    // bannerView 物件初始化, 帶入自訂的origin
    if (!bannerView) {
        bannerView = [[TADBannerView alloc] initWithAdSize:kTADAdSizeBanner origin:CGPointMake(0, self.view.frame.size.height - 50)];
    }
    
    // 必須要設定delegate
    bannerView.delegate = self;
    
    // 設定 AD Unit ID
    bannerView.adUnitID = [_YOUR_AD_UNIT_ID_];
    
    // 設定 rootViewController
    bannerView.rootViewController = self;
    
    // 載入廣告
    [bannerView loadRequest:request];
}



特別注意

在 ViewController 的 view 即將消失前, 必須要將 bannerView 本身以及其 delegate 設定為 nil

// ExpandableViewController.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首頁