「SDK8 Banner」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
行 29: | 行 29: | ||
:* 請求廣告 | :* 請求廣告 | ||
== BannerViewController.swift == | |||
<source> | |||
// 匯入 TAMedia SDK 定義 | |||
import TAMediaAdsFramework | |||
class BannerViewController: : UIViewController { | class BannerViewController: : UIViewController { | ||
// 宣告 TADBannerView 變數 | |||
var banner: TADBannerView? | var banner: TADBannerView? | ||
requestAd() | requestAd() | ||
行 45: | 行 45: | ||
func requestAd() { | func requestAd() { | ||
let request = TADRequest() | let request = TADRequest() | ||
request.showLog = true | request.showLog = true | ||
行 64: | 行 62: | ||
} | } | ||
} | } | ||
</source> | |||
== TADBannerViewDelegate == | == TADBannerViewDelegate == | ||
<source> | |||
extension BannerViewController: TADBannerViewDelegate { | extension BannerViewController: TADBannerViewDelegate { | ||
// Ad Request Lifecycle Notifications | |||
// 廣告取得成功 | |||
func adViewDidReceiveAd(_ view: TADBannerView!) { | func adViewDidReceiveAd(_ view: TADBannerView!) { | ||
} | } | ||
// 廣告取得失敗 | |||
func adView(_ view: TADBannerView!, didFailToReceiveAdWithError error: TADRequestError!) { | func adView(_ view: TADBannerView!, didFailToReceiveAdWithError error: TADRequestError!) { | ||
} | } | ||
// 廣告即將被呈現之前被呼叫 | |||
func adViewWillPresentScreen(_ adView: TADBannerView!) { | func adViewWillPresentScreen(_ adView: TADBannerView!) { | ||
} | } | ||
// 廣告即將被關閉之前被呼叫 | |||
func adViewWillDismissScreen(_ adView: TADBannerView!) { | func adViewWillDismissScreen(_ adView: TADBannerView!) { | ||
} | } | ||
// 廣告被關閉之後被呼叫 | |||
func adViewDidDismissScreen(_ adView: TADBannerView!) { | func adViewDidDismissScreen(_ adView: TADBannerView!) { | ||
} | } | ||
// 應用程式即將進入背景執行或中止運作前被呼叫 | |||
func adViewWillLeaveApplication(_ adView: TADBannerView!) { | func adViewWillLeaveApplication(_ adView: TADBannerView!) { | ||
} | } | ||
行 96: | 行 95: | ||
} | } | ||
</source> | |||
[[IOS SDK 2.0 Developer Guide|回 iOS首頁]] | [[IOS SDK 2.0 Developer Guide|回 iOS首頁]] |
於 2021年8月5日 (四) 02:53 的修訂
橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告
Banners 大小種類
BANNER S | BANNER M | BANNER L |
---|---|---|
320x50 | 320x250 | 1200x627 |
加入 TADBannerView
TADBannerView 物件是 UIView 的 subclass, 呈現html5橫幅廣告 加入橫幅廣告的簡單七步驟, 建議在viewController裡執行
- 匯入 TAMediaAdsFramework
- 在 UIViewController裡宣告 TADBannerView 變數
- 建立橫幅廣告
- 設定Unit ID
- 設定 rootViewController
- 將橫幅廣告加入UI
- 請求廣告
BannerViewController.swift
// 匯入 TAMedia SDK 定義
import TAMediaAdsFramework
class BannerViewController: : UIViewController {
// 宣告 TADBannerView 變數
var banner: TADBannerView?
requestAd()
override func viewDidLoad() {
super.viewDidLoad()
requestAd()
}
func requestAd() {
let request = TADRequest()
request.showLog = true
request.setLocationWithLatitude(25.02246916213678, longitude: 121.54834205241194, accuracy: 1)
if bannerType == .Banner320x250 {
banner = TADBannerView.init(adSize: kTADAdSizeMediumRectangle, origin: CGPoint(x: 10, y: self.view.frame.size.height - 100))
} else if bannerType == .Banner1200x627 {
banner = TADBannerView.init(adSize: TADAdSize1200x627RatioBannerWithWidth(300), origin: CGPoint(x: 10, y: self.view.frame.size.height - 450))
}
banner?.delegate = self
banner?.adUnitID = slotId
banner?.rootViewController = self
banner?.turnOnMicrophone = false
banner?.load(request)
}
}
TADBannerViewDelegate
extension BannerViewController: TADBannerViewDelegate {
// Ad Request Lifecycle Notifications
// 廣告取得成功
func adViewDidReceiveAd(_ view: TADBannerView!) {
}
// 廣告取得失敗
func adView(_ view: TADBannerView!, didFailToReceiveAdWithError error: TADRequestError!) {
}
// 廣告即將被呈現之前被呼叫
func adViewWillPresentScreen(_ adView: TADBannerView!) {
}
// 廣告即將被關閉之前被呼叫
func adViewWillDismissScreen(_ adView: TADBannerView!) {
}
// 廣告被關閉之後被呼叫
func adViewDidDismissScreen(_ adView: TADBannerView!) {
}
// 應用程式即將進入背景執行或中止運作前被呼叫
func adViewWillLeaveApplication(_ adView: TADBannerView!) {
}
}