「SDK8 InReadAnchor」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
imported>Wikiuser
imported>Wikiuser
行 5: 行 5:


== 加入 TADInReadAnchor ==
== 加入 TADInReadAnchor ==
*匯入廣告標頭檔#import <TAMediaAdsFramework/TAMediaAdsFramework.h>
*匯入廣告標頭檔import TAMediaAdsFramework
*在 UIViewController 中宣告 TADInReadAdAnchor 執行個體
*在 UIViewController 中宣告 TADInReadAdAnchor 執行個體
*帶入需要呈現廣告的ViewController,初始化廣告
*帶入需要呈現廣告的ViewController,初始化廣告
*建立Request請求廣告
*建立Request請求廣告
@interface AnchorSampleVC () <TADInReadAnchorDelegate>
 
@property (nonatomic,strong) TADInReadAnchor *inReadAnchorAd;
== AnchorViewController.swift ==
@end
<source>
  @implementation AnchorSampleVC
  @implementation AnchorSampleVC
   
  class AnchorViewController: UIViewController {
- (void)viewDidLoad {
 
    [super viewDidLoad];
    @IBOutlet weak var resultLabel: UILabel!
    [self requestAnchor];
    var anchorView: TADInReadAnchor?
}
 
- (void)viewWillAppear:(BOOL)animated {
    override func viewDidLoad() {
    [super viewWillAppear:animated];
        super.viewDidLoad()
      '''// 通知廣告頁面將出現'''
        requestAd()
    [self.inReadAnchorAd viewWillAppear];
    }
}
 
- (void)viewWillDisappear:(BOOL)animated {
    func requestAd() {
    [super viewWillDisappear:animated];
        let request = TADRequest()
    '''// 通知廣告頁面將消失'''
        // 顯示log
    [self.inReadAnchorAd viewWillDisappear];
        request.showLog = true
}
- (void)requestAnchor {
    '''//帶入需要呈現廣告的ViewController'''
    self.inReadAnchorAd = [[TADInReadAnchor alloc] initAnchorWithViewController:self];
    '''// 設定 AD Unit ID'''
    self.inReadAnchorAd.adUnitID = [_YOUR_AD_UNIT_ID_];
 
    '''// 必須要設定delegate'''
    self.inReadAnchorAd.delegate = self;
    TADRequest *request = [TADRequest request];
    '''// 顯示log'''   
    request.showLog = YES;
      
      
    '''// Type: TADGender'''
        // set gender
    request.gender = [_GENDER_];
        request.gender = [_GENDER_]
      
      
    '''// Set birthday'''
        // Set birthday
    [request setBirthdayWithYear:[_YEAR_] month:[_MONTH_] day:[_DAY_]];
        request.setBirthdayWithYear([_YEAR_], month: [_MONTH_], day: [_DAY_])
      
      
    '''// Set location'''
        // Set location
    [request setLocationWithLatitude:[_LATITUDE_] longitude:[_LONGITUDE_] accuracy:[_ACCURACY_]];   
        request.setLocationWithLatitude(latitude: [_LATITUDE_], longitude: :[_LONGITUDE_], accuracy: [_ACCURACY_])
 
    '''// 載入廣告'''
        anchorView = TADInReadAnchor(anchorWith: self)
    [self.inReadAnchorAd loadRequest:request];
        // 設定 AD Unit ID
}
        anchorView?.adUnitID = [_YOUR_AD_UNIT_ID_]
 
        // 必須要設定delegate
        anchorView?.delegate = self
 
        // 建立Request請求廣告
        anchorView?.load(request)
 
        if let inread = anchorView {
            self.view.addSubview(inread)
        }
    }
}
</source>


== TADInReadAdRectDelegate ==
== TADInReadAdRectDelegate ==
'''// 廣告載入成功後被呼叫'''
<source>
- (void)anchorDidReceiveAd:(TADInReadAnchor *)anchor {
extension AnchorViewController: TADInReadAnchorDelegate {
}
    // 廣告取得成功
    func anchorDidReceiveAd(_ anchor: TADInReadAnchor!) {
'''// 廣告載入失敗後被呼叫'''
    }
- (void)anchor:(TADInReadAnchor *)anchor didFailToReceiveAdWithError:(TADRequestError *)error {
 
}
    // 廣告取得失敗
  '''// 廣告將出現時呼叫'''
    func anchor(_ anchor: TADInReadAnchor!, didFailToReceiveAdWithError error: TADRequestError!) {
- (void)anchorWillShow:(TADInReadAnchor *)anchor {
    }
}
 
  '''// 應用程式及將改在背景執行或中止運作前被呼叫'''
    // 廣告即將被呈現之前被呼叫
- (void)anchorWillLeaveApplication:(TADInReadAnchor *)anchor {
    func anchorWillShow(_ anchor: TADInReadAnchor!) {
}
    }
 
'''//使用者將anchor關閉時呼叫'''
    // 廣告被關閉之後被呼叫
- (void)anchorUserPressedCloseAd {
    func anchorUserPressedCloseAd() {
    //user關閉anchor後 須將廣告及delegate設為nil
        //user關閉anchor後 須將廣告及delegate設為nil
    self.inReadAnchorAd.delegate = nil;
        self.anchorView?.delegate = nil;
    self.inReadAnchorAd = nil;
        self.anchorView = nil;
}
    }
== 特別注意 ==
 
#viewController消失前, 必須將 inReadAnchor 及其 delegate 設為 nil
    // 應用程式即將進入背景執行或中止運作前被呼叫
     - (IBAction)backButtonPressed:(id)sender {
     func anchorWillLeaveApplication(_ anchor: TADInReadAnchor!) {
        [self dismissViewControllerAnimated:YES completion:nil];
            if (self.inReadAnchorAd != nil) {
                self.inReadAnchorAd.delegate = nil;
                self.inReadAnchorAd = nil;
            }
     }
     }
}
</source>

於 2021年8月5日 (四) 07:18 的修訂

回InReadAd首頁

簡介

Anchor廣告的特性是會位於ViewController正下方,圖片依照640x280、影片依照560x315的比例,在不超過畫面高度1/3內,自動fit螢幕寬度,當螢幕轉向時因高度改變會依照上述特性調整廣告尺寸。

加入 TADInReadAnchor

  • 匯入廣告標頭檔import TAMediaAdsFramework
  • 在 UIViewController 中宣告 TADInReadAdAnchor 執行個體
  • 帶入需要呈現廣告的ViewController,初始化廣告
  • 建立Request請求廣告

AnchorViewController.swift

 @implementation AnchorSampleVC
 class AnchorViewController: UIViewController {

    @IBOutlet weak var resultLabel: UILabel!
    var anchorView: TADInReadAnchor?

    override func viewDidLoad() {
        super.viewDidLoad()
        requestAd()
    }

    func requestAd() {
        let request = TADRequest()
        // 顯示log
        request.showLog = true
     
        // set gender
        request.gender = [_GENDER_]
     
        // Set birthday
        request.setBirthdayWithYear([_YEAR_], month: [_MONTH_], day: [_DAY_])
     
        // Set location
        request.setLocationWithLatitude(latitude: [_LATITUDE_], longitude: :[_LONGITUDE_], accuracy: [_ACCURACY_])

        anchorView = TADInReadAnchor(anchorWith: self)
        // 設定 AD Unit ID
        anchorView?.adUnitID = [_YOUR_AD_UNIT_ID_]

        // 必須要設定delegate
        anchorView?.delegate = self

        // 建立Request請求廣告
        anchorView?.load(request)

        if let inread = anchorView {
            self.view.addSubview(inread)
        }
    }
}

TADInReadAdRectDelegate

extension AnchorViewController: TADInReadAnchorDelegate {
    // 廣告取得成功
    func anchorDidReceiveAd(_ anchor: TADInReadAnchor!) {
    }

    // 廣告取得失敗
    func anchor(_ anchor: TADInReadAnchor!, didFailToReceiveAdWithError error: TADRequestError!) {
    }

    // 廣告即將被呈現之前被呼叫
    func anchorWillShow(_ anchor: TADInReadAnchor!) {
    }

    // 廣告被關閉之後被呼叫
    func anchorUserPressedCloseAd() {
        //user關閉anchor後 須將廣告及delegate設為nil
        self.anchorView?.delegate = nil;
        self.anchorView = nil;
    }

    // 應用程式即將進入背景執行或中止運作前被呼叫
    func anchorWillLeaveApplication(_ anchor: TADInReadAnchor!) {
    }
}