「SDK8 Banner」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
imported>Wikiuser |
||
行 8: | 行 8: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! | ! BannerDefault | ||
! | ! SmartBanner | ||
! | ! MediumRectangle | ||
! LargeRectangle | |||
|- | |- | ||
| 320x50 | | 320x50 | ||
| portrait: full widthx50(phone), full widthx90(pad), lanscape: full widthx32(phone), full widthx90(pad) | |||
| 320x250 | | 320x250 | ||
| 1200x627 | | 1200x627 | ||
行 33: | 行 35: | ||
import TAMediaAdsFramework | import TAMediaAdsFramework | ||
@objc enum BannerType: Int { | |||
case BannerDefault | |||
case Banner320x250 | |||
case Banner1200x627 | |||
case SmartBanner | |||
} | |||
class BannerViewController: : UIViewController { | class BannerViewController: : UIViewController { | ||
// 宣告 TADBannerView 變數 | // 宣告 TADBannerView 變數 | ||
行 49: | 行 58: | ||
// 依Banner種類設定AD Size | // 依Banner種類設定AD Size | ||
if bannerType == .BannerDefault { | |||
banner = TADBannerView.init(adSize: kTADAdSizeBanner, origin: CGPoint(x: 10, y: self.view.frame.size.height - 100)) | |||
} | |||
if bannerType == .Banner320x250 { | if bannerType == .Banner320x250 { | ||
banner = TADBannerView.init(adSize: kTADAdSizeMediumRectangle, origin: CGPoint(x: 10, y: self.view.frame.size.height - 100)) | banner = TADBannerView.init(adSize: kTADAdSizeMediumRectangle, origin: CGPoint(x: 10, y: self.view.frame.size.height - 100)) | ||
} else if bannerType == .Banner1200x627 { | } else if bannerType == .Banner1200x627 { | ||
banner = TADBannerView.init(adSize: TADAdSize1200x627RatioBannerWithWidth(300), origin: CGPoint(x: 10, y: self.view.frame.size.height - 450)) | banner = TADBannerView.init(adSize: TADAdSize1200x627RatioBannerWithWidth(300), origin: CGPoint(x: 10, y: self.view.frame.size.height - 450)) | ||
} else if bannerType == .SmartBanner { | |||
banner = TADBannerView.init(adSize: kTADAdSizeSmartBannerPortrait, origin: CGPoint(x: 10, y: self.view.frame.size.height - 450)) | |||
} | } | ||
於 2021年8月5日 (四) 04:16 的修訂
橫幅廣告只占螢幕的一小部分,使用者點擊後可以有全螢幕的瀏覽體驗,簡單的建立方式讓開發者輕鬆置入廣告
Banners 大小種類
BannerDefault | SmartBanner | MediumRectangle | LargeRectangle |
---|---|---|---|
320x50 | portrait: full widthx50(phone), full widthx90(pad), lanscape: full widthx32(phone), full widthx90(pad) | 320x250 | 1200x627 |
加入 TADBannerView
TADBannerView 物件是 UIView 的 subclass, 呈現html5橫幅廣告 加入橫幅廣告的簡單七步驟, 建議在viewController裡執行
- 匯入 TAMediaAdsFramework
- 在 UIViewController裡宣告 TADBannerView 變數
- 建立橫幅廣告,AD Size
- 設定Unit ID
- 設定 rootViewController
- 請求廣告
BannerViewController.swift
// 匯入 TAMedia SDK 定義
import TAMediaAdsFramework
@objc enum BannerType: Int {
case BannerDefault
case Banner320x250
case Banner1200x627
case SmartBanner
}
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)
// 依Banner種類設定AD Size
if bannerType == .BannerDefault {
banner = TADBannerView.init(adSize: kTADAdSizeBanner, origin: CGPoint(x: 10, y: self.view.frame.size.height - 100))
}
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))
} else if bannerType == .SmartBanner {
banner = TADBannerView.init(adSize: kTADAdSizeSmartBannerPortrait, 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!) {
}
}