「SDK8 AdMob Mediation Interstitial」修訂間的差異
跳至導覽
跳至搜尋
imported>Wikiuser |
CharlesWang(留言 | 貢獻) |
||
(未顯示由 2 位使用者於中間所作的 8 次修訂) | |||
行 1: | 行 1: | ||
== <b>簡介</b> == | == <b>簡介</b> == | ||
首先先完成 mediation 基本 setup [[AdMob Mediation Setup]], TADCustomEvent 將會透過此客製化 class 取得 TADInterstitial。 | |||
== <b>實作方式</b> == | == <b>實作方式</b> == | ||
TADCustomEventInterstitial.swift | |||
<source> | |||
class TADCustomEventInterstitial: NSObject, GADMediationInterstitialAd { | |||
var delegate: GADMediationInterstitialAdEventDelegate? | |||
var interstitialView: TADInterstitial? | |||
var completionHandler: GADMediationInterstitialLoadCompletionHandler? | |||
override required init() { | |||
super.init() | |||
} | } | ||
func loadInterstitial(for adConfiguration: GADMediationInterstitialAdConfiguration, | |||
completionHandler: @escaping GADMediationInterstitialLoadCompletionHandler) { | |||
// 將 adConfiguration 物件裡的資訊轉入 TADRequest 物件 | |||
func | |||
let tadRequest = TADRequest() | let tadRequest = TADRequest() | ||
tadRequest.isTesting = | tadRequest.isTesting = adConfiguration.isTestRequest | ||
tadRequest.setLocationWithLatitude(adConfiguration.userLatitude, longitude: adConfiguration.userLongitude, accuracy: adConfiguration.userLocationAccuracyInMeters) | |||
tadRequest.setLocationWithLatitude( | |||
self.completionHandler = completionHandler | |||
self.interstitialView = TADInterstitial() | self.interstitialView = TADInterstitial() | ||
self.interstitialView?.delegate = self | self.interstitialView?.delegate = self | ||
self.interstitialView?.adUnitID = adConfiguration.credentials.settings["parameter"] as? String | |||
self.interstitialView?.adUnitID = | self.interstitialView?.turnOnMicrophone = false | ||
self.interstitialView?.load(tadRequest) | self.interstitialView?.load(tadRequest) | ||
} | } | ||
func present( | func present(from viewController: UIViewController) { | ||
interstitialView?.present(fromRootViewController: | interstitialView?.present(fromRootViewController: viewController) | ||
} | } | ||
} | |||
// MARK: TADInterstitialDelegate | |||
extension TADCustomEventInterstitial: TADInterstitialDelegate { | |||
func interstitialDidReceiveAd(_ ad: TADInterstitial!) { | func interstitialDidReceiveAd(_ ad: TADInterstitial!) { | ||
print("CustomInterstitial - interstitialDidReceiveAd!!") | print("CustomInterstitial - interstitialDidReceiveAd!!") | ||
if let handler = completionHandler { | |||
delegate = handler(self, nil) | |||
} | |||
} | } | ||
func interstitial(_ ad: TADInterstitial!, didFailToReceiveAdWithError error: TADRequestError!) { | func interstitial(_ ad: TADInterstitial!, didFailToReceiveAdWithError error: TADRequestError!) { | ||
print("CustomInterstitial - didFailToReceiveAdWithError!! error: \(String(describing: error))") | print("CustomInterstitial - didFailToReceiveAdWithError!! error: \(String(describing: error))") | ||
self. | if let handler = completionHandler { | ||
delegate = handler(nil, error) | |||
} | |||
// 需手動設為 nil,auto release 在 admob SDK 會造成在未在 main thread 執行 | |||
self.interstitialView?.delegate = nil | |||
self.interstitialView = nil | |||
} | } | ||
func interstitialWillPresentScreen(_ ad: TADInterstitial!) { | func interstitialWillPresentScreen(_ ad: TADInterstitial!) { | ||
print("CustomInterstitial - interstitialWillPresentScreen!!") | print("CustomInterstitial - interstitialWillPresentScreen!!") | ||
delegate?.reportImpression() | |||
} | } | ||
func interstitialDidDismissScreen(_ ad: TADInterstitial!) { | func interstitialDidDismissScreen(_ ad: TADInterstitial!) { | ||
print("CustomInterstitial - interstitialWillDismissScreen!!") | print("CustomInterstitial - interstitialWillDismissScreen!!") | ||
delegate?.didDismissFullScreenView() | |||
} | } | ||
func interstitialWillLeaveApplication(_ ad: TADInterstitial!) { | func interstitialWillLeaveApplication(_ ad: TADInterstitial!) { | ||
print("CustomInterstitial - interstitialWillLeaveApplication!!") | print("CustomInterstitial - interstitialWillLeaveApplication!!") | ||
delegate?.reportClick() | |||
} | } | ||
} | |||
</source> | |||
== Interstitial畫面展示 == | == Interstitial畫面展示 == | ||
行 95: | 行 76: | ||
| align="center" | 插頁式廣告呈現 | | align="center" | 插頁式廣告呈現 | ||
|- | |- | ||
| align="center" | [[檔案:2021-08-06-AdMob_Interstitial.jpeg]] | | align="center" | [[檔案:2021-08-06-AdMob_Interstitial.jpeg|x300px]] | ||
|} | |} | ||
[[SDK8 Google AdMob Mediation|回 AdMob Mediation]] |
於 2023年4月7日 (五) 09:56 的最新修訂
簡介
首先先完成 mediation 基本 setup AdMob Mediation Setup, TADCustomEvent 將會透過此客製化 class 取得 TADInterstitial。
實作方式
TADCustomEventInterstitial.swift
class TADCustomEventInterstitial: NSObject, GADMediationInterstitialAd {
var delegate: GADMediationInterstitialAdEventDelegate?
var interstitialView: TADInterstitial?
var completionHandler: GADMediationInterstitialLoadCompletionHandler?
override required init() {
super.init()
}
func loadInterstitial(for adConfiguration: GADMediationInterstitialAdConfiguration,
completionHandler: @escaping GADMediationInterstitialLoadCompletionHandler) {
// 將 adConfiguration 物件裡的資訊轉入 TADRequest 物件
let tadRequest = TADRequest()
tadRequest.isTesting = adConfiguration.isTestRequest
tadRequest.setLocationWithLatitude(adConfiguration.userLatitude, longitude: adConfiguration.userLongitude, accuracy: adConfiguration.userLocationAccuracyInMeters)
self.completionHandler = completionHandler
self.interstitialView = TADInterstitial()
self.interstitialView?.delegate = self
self.interstitialView?.adUnitID = adConfiguration.credentials.settings["parameter"] as? String
self.interstitialView?.turnOnMicrophone = false
self.interstitialView?.load(tadRequest)
}
func present(from viewController: UIViewController) {
interstitialView?.present(fromRootViewController: viewController)
}
}
// MARK: TADInterstitialDelegate
extension TADCustomEventInterstitial: TADInterstitialDelegate {
func interstitialDidReceiveAd(_ ad: TADInterstitial!) {
print("CustomInterstitial - interstitialDidReceiveAd!!")
if let handler = completionHandler {
delegate = handler(self, nil)
}
}
func interstitial(_ ad: TADInterstitial!, didFailToReceiveAdWithError error: TADRequestError!) {
print("CustomInterstitial - didFailToReceiveAdWithError!! error: \(String(describing: error))")
if let handler = completionHandler {
delegate = handler(nil, error)
}
// 需手動設為 nil,auto release 在 admob SDK 會造成在未在 main thread 執行
self.interstitialView?.delegate = nil
self.interstitialView = nil
}
func interstitialWillPresentScreen(_ ad: TADInterstitial!) {
print("CustomInterstitial - interstitialWillPresentScreen!!")
delegate?.reportImpression()
}
func interstitialDidDismissScreen(_ ad: TADInterstitial!) {
print("CustomInterstitial - interstitialWillDismissScreen!!")
delegate?.didDismissFullScreenView()
}
func interstitialWillLeaveApplication(_ ad: TADInterstitial!) {
print("CustomInterstitial - interstitialWillLeaveApplication!!")
delegate?.reportClick()
}
}
Interstitial畫面展示
插頁式廣告呈現 |