「SDK8 Banner」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser (新頁面: test) |
imported>Wikiuser |
||
行 1: | 行 1: | ||
橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告<br><br> | |||
[[IOS SDK Developer Guide v2|回 iOS首頁]]<br> | |||
== Banners 大小種類 == | |||
{| class="wikitable" | |||
|- | |||
! 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() { | |||
self.resultLabel.text = "Loading..." | |||
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!) { | |||
} | |||
} | |||
[[IOS SDK 2.0 Developer Guide|回 iOS首頁]] |
於 2021年8月4日 (三) 08:46 的修訂
橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告
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 定義
class BannerViewController: : UIViewController {
// 宣告 TADBannerView 變數 var banner: TADBannerView? requestAd()
override func viewDidLoad() { super.viewDidLoad() requestAd() }
func requestAd() { self.resultLabel.text = "Loading..."
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!) { }
}