「SDK8 AdMob Mediation Interstitial」修訂間的差異
跳至導覽
跳至搜尋
CharlesWang(留言 | 貢獻) |
CharlesWang(留言 | 貢獻) |
||
(未顯示同一使用者於中間所作的 1 次修訂) | |||
行 1: | 行 1: | ||
== <b>簡介</b> == | == <b>簡介</b> == | ||
首先先完成 mediation 基本 setup [[AdMob Mediation Setup]], TADCustomEvent 將會透過此客製化 class 取得 TADInterstitial。 | 首先先完成 mediation 基本 setup [[AdMob Mediation Setup]], TADCustomEvent 將會透過此客製化 class 取得 TADInterstitial。 | ||
行 212: | 行 78: | ||
| align="center" | [[檔案:2021-08-06-AdMob_Interstitial.jpeg|x300px]] | | 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畫面展示
插頁式廣告呈現 |