「SDK8 Banner」修訂間的差異
imported>Wikiuser |
CharlesWang(留言 | 貢獻) |
||
(未顯示由 2 位使用者於中間所作的 17 次修訂) | |||
行 1: | 行 1: | ||
<!-- [[IOS SDK Developer Guide v2|回 iOS首頁]]<br> --> | |||
[[SDK8 iOS SDK Developer Guide|回 SDK 8首頁]]<br> | |||
== 簡介 == | |||
橫幅廣告只占螢幕的一小部分,使用者點擊後可以進入廣告頁面進行瀏覽,簡單的建立方式讓開發者輕鬆置入廣告。<br> | |||
== 串接準備 == | |||
開始串接前請間確定已將 TAmedia SDK 整合至專案,並且完成[http://wiki.tamedia.com.tw/wiki/SDK8_Getting_Started_Guide#.E5.88.9D.E5.A7.8B.E5.8C.96.E8.A1.8C.E5.8B.95.E5.BB.A3.E5.91.8A_SDK 初始化 SDK]步驟,若您尚未完成請先參考[[SDK8 Getting Started Guide |開始使用教學]]完成相關設定。 | |||
== Reference document == | |||
[http://wiki.tamedia.com.tw/iosDoc/Classes/TADBannerView.html Banner] | |||
== Banners 大小種類 == | == Banners 大小種類 == | ||
行 8: | 行 15: | ||
{| class="wikitable" | {| class="wikitable" | ||
|- | |- | ||
! | ! BannerDefault | ||
! | ! SmartBanner | ||
! | ! MediumRectangle | ||
! LargeRectangle | |||
|- | |- | ||
| 320x50 | | 320x50 | ||
| portrait: full widthx50(phone), full widthx90(pad)<br> lanscape: full widthx32(phone), full widthx90(pad) | |||
| 320x250 | | 320x250 | ||
| 1200x627 | | 1200x627 | ||
|} | |} | ||
== 加入 TADBannerView == | == 加入 TADBannerView == | ||
行 23: | 行 31: | ||
:* 匯入 TAMediaAdsFramework | :* 匯入 TAMediaAdsFramework | ||
:* 在 UIViewController裡宣告 TADBannerView 變數 | :* 在 UIViewController裡宣告 TADBannerView 變數 | ||
:* | :* 建立橫幅廣告,AD Size | ||
:* 設定Unit ID | :* 設定Unit ID | ||
:* 設定 rootViewController | :* 設定 rootViewController | ||
:* 請求廣告 | :* 請求廣告 | ||
== BannerViewController | == BannerViewController == | ||
< | <nowiki>// 匯入 TAMedia SDK 定義 | ||
// 匯入 TAMedia SDK 定義 | |||
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: | 行 62: | ||
request.setLocationWithLatitude(25.02246916213678, longitude: 121.54834205241194, accuracy: 1) | request.setLocationWithLatitude(25.02246916213678, longitude: 121.54834205241194, accuracy: 1) | ||
if bannerType == .Banner320x250 { | // 依Banner種類設定AD Size | ||
banner = TADBannerView.init(adSize: kTADAdSizeMediumRectangle, origin: CGPoint(x: 10, y: self.view.frame.size.height - | if bannerType == .BannerDefault { | ||
banner = TADBannerView.init(adSize: kTADAdSizeBanner, origin: CGPoint(x: 10, y: self.view.frame.size.height - 100)) | |||
banner?.adUnitID = Constants.BannerAd320x50SlotID | |||
} else if bannerType == .Banner320x250 { | |||
banner = TADBannerView.init(adSize: kTADAdSizeMediumRectangle, origin: CGPoint(x: 10, y: self.view.frame.size.height - 300)) | |||
banner?.adUnitID = Constants.BannerAd320x250SlotID | |||
} 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)) | ||
banner?.adUnitID = Constants.BannerAd1200x627SlotID | |||
} else if bannerType == .SmartBanner { | |||
banner = TADBannerView.init(adSize: kTADAdSizeSmartBannerPortrait, origin: CGPoint(x: 0, y: self.view.frame.size.height - 100)) | |||
banner?.adUnitID = Constants.BannerAd320x50SlotID | |||
} | } | ||
行 62: | 行 84: | ||
} | } | ||
} | } | ||
</ | </nowiki> | ||
== TADBannerViewDelegate == | == TADBannerViewDelegate == | ||
< | <nowiki> | ||
extension BannerViewController: TADBannerViewDelegate { | extension BannerViewController: TADBannerViewDelegate { | ||
// Ad Request Lifecycle Notifications | // Ad Request Lifecycle Notifications | ||
行 95: | 行 117: | ||
} | } | ||
</ | </nowiki> | ||
[[IOS SDK 2.0 Developer Guide|回 iOS首頁]] | [[SDK8 iOS SDK Developer Guide|回 SDK 8首頁]]<br> | ||
<!-- [[IOS SDK 2.0 Developer Guide|回 iOS首頁]] --> |
於 2022年4月21日 (四) 08:16 的最新修訂
簡介
橫幅廣告只占螢幕的一小部分,使用者點擊後可以進入廣告頁面進行瀏覽,簡單的建立方式讓開發者輕鬆置入廣告。
串接準備
開始串接前請間確定已將 TAmedia SDK 整合至專案,並且完成初始化 SDK步驟,若您尚未完成請先參考開始使用教學完成相關設定。
Reference document
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
// 匯入 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)) banner?.adUnitID = Constants.BannerAd320x50SlotID } else if bannerType == .Banner320x250 { banner = TADBannerView.init(adSize: kTADAdSizeMediumRectangle, origin: CGPoint(x: 10, y: self.view.frame.size.height - 300)) banner?.adUnitID = Constants.BannerAd320x250SlotID } else if bannerType == .Banner1200x627 { banner = TADBannerView.init(adSize: TADAdSize1200x627RatioBannerWithWidth(300), origin: CGPoint(x: 10, y: self.view.frame.size.height - 450)) banner?.adUnitID = Constants.BannerAd1200x627SlotID } else if bannerType == .SmartBanner { banner = TADBannerView.init(adSize: kTADAdSizeSmartBannerPortrait, origin: CGPoint(x: 0, y: self.view.frame.size.height - 100)) banner?.adUnitID = Constants.BannerAd320x50SlotID } 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!) { } }