檢視 SDK8 AdMob Mediation Banner 的原始碼
←
SDK8 AdMob Mediation Banner
跳至導覽
跳至搜尋
由於下列原因,您沒有權限進行編輯此頁面的動作:
您請求的操作只有這個群組的使用者能使用:
使用者
您可以檢視並複製此頁面的原始碼。
== <b>簡介</b> == 首先先完成 mediation 基本 setup [[AdMob Mediation Setup]], TADCustomEvent 將會透過此客製化 class 取得 TADBanner。 == <b>TAMedia Banner 廣告支援格式</b> == {| class="wikitable" style="width:50%" |- ! 廣告格式 (寬度x高度) !! AdMob 對應常數值 |- | align="center"|BANNER 320x50 || align="center"|kGADAdSizeBanner |- | align="center"|BANNER 1200x627 || align="center"|GADAdSizeFromCGSize(相對應比例CGSize) |- | align="center"|BANNER 320x50 || align="center"|kGADAdSizeMediumRectangle |- |} == <b>實作方式</b> == TADCustomEventBanner.swift <source> import Foundation import GoogleMobileAds import TAMediaAdsFramework class TADCustomEventBanner: NSObject, GADMediationBannerAd { var view: UIView { return bannerView ?? UIView() } var bannerView: TADBannerView? /// The ad event delegate to forward ad rendering events to the Google Mobile Ads SDK. var delegate: GADMediationBannerAdEventDelegate? /// Completion handler called after ad load var completionHandler: GADMediationBannerLoadCompletionHandler? func loadBanner(for adConfiguration: GADMediationBannerAdConfiguration, completionHandler: @escaping GADMediationBannerLoadCompletionHandler) { let tadRequest = TADRequest() tadRequest.isTesting = adConfiguration.isTestRequest tadRequest.setLocationWithLatitude(adConfiguration.userLatitude, longitude: adConfiguration.userLongitude, accuracy: adConfiguration.userLocationAccuracyInMeters) let adSize = adConfiguration.adSize let adRatio: CGFloat = floor((adSize.size.width/adSize.size.height)*100)/100 let ta1200x627AdRatio: CGFloat = floor((1200.0/627)*100)/100 /// 依據不同的 size 設定 if GADAdSizeEqualToSize(adSize, GADAdSizeBanner) { self.bannerView = TADBannerView(adSize: kTADAdSizeBanner) } else if GADAdSizeEqualToSize(adSize, GADAdSizeMediumRectangle) { self.bannerView = TADBannerView(adSize: kTADAdSizeMediumRectangle) } else if adRatio == ta1200x627AdRatio { self.bannerView = TADBannerView(adSize: TADAdSize1200x627RatioBannerWithWidth(adSize.size.width)) } else { let error = NSError(domain: "com.TAmedia.TADCustomBanner", code: GADErrorCode.mediationInvalidAdSize.rawValue, userInfo: nil) delegate = completionHandler(nil, error) } self.completionHandler = completionHandler self.bannerView?.delegate = self self.bannerView?.adUnitID = adConfiguration.credentials.settings["parameter"] as? String self.bannerView?.turnOnMicrophone = false self.bannerView?.rootViewController = adConfiguration.topViewController self.bannerView?.load(tadRequest) } } // MARK: TADBannerViewDelegate extension TADCustomEventBanner: TADBannerViewDelegate { func adViewDidReceiveAd(_ view: TADBannerView!) { print("CustomBanner - adViewDidReceiveAd!!") if let handler = completionHandler { delegate = handler(self, nil) } } func adView(_ view: TADBannerView!, didFailToReceiveAdWithError error: TADRequestError!) { print("CustomBanner - didFailToReceiveAdWithError!! error: \(String(describing: error))") if let handler = completionHandler { delegate = handler(nil, error) } } func adViewWillPresentScreen(_ adView: TADBannerView!) { print("CustomBanner - adViewWillPresentScreen!!") } func adViewWillDismissScreen(_ adView: TADBannerView!) { print("CustomBanner - adViewWillDismissScreen!!") } func adViewDidDismissScreen(_ adView: TADBannerView!) { print("CustomBanner - adViewDidDismissScreen!!") } func adViewWillLeaveApplication(_ adView: TADBannerView!) { print("CustomBanner - adViewWillLeaveApplication!!") delegate?.reportClick() } } </source> == <b> Banner 畫面展示</b> == {| width="70%" border="1" |- | align="center" | 320x50 | align="center" | 1200x627 |- | align="center" | [[檔案:2021-08-06-AdMob_Banner320.PNG|x300px]] | align="center" | [[檔案:2021-08-06-AdMob_Banner1200.PNG|x300px]] |} [[SDK8 Google AdMob Mediation|回 AdMob Mediation]]
返回到「
SDK8 AdMob Mediation Banner
」。
導覽選單
個人工具
登入
命名空間
頁面
討論
變體
已展開
已摺疊
視圖
閱讀
檢視原始碼
檢視歷史
更多
已展開
已摺疊
搜尋
導覽
首頁
近期變更
隨機頁面
有關 MediaWiki 的說明
工具
連結至此的頁面
相關變更
特殊頁面
頁面資訊