「AdMob Mediation Setup」修訂間的差異

出自TAMedia
跳至導覽 跳至搜尋
 
(未顯示同一使用者於中間所作的 3 次修訂)
行 5: 行 5:
在專案中加入與 Custom Event 對應的 Class,其中 Custom Event 的 Class Name 需要和專案新增的 Class Name 保持一致
在專案中加入與 Custom Event 對應的 Class,其中 Custom Event 的 Class Name 需要和專案新增的 Class Name 保持一致
例如新增的 Class Name 為 TADCustomEvent,Custom Event 的 Class Name 則必須是 專案名稱.TADCustomEvent。(以 Swift 編寫的專案需加上專案名稱;若為以 OC編寫,則放入 Class Name,https://developers.google.com/admob/ios/custom-events/setup#create)
例如新增的 Class Name 為 TADCustomEvent,Custom Event 的 Class Name 則必須是 專案名稱.TADCustomEvent。(以 Swift 編寫的專案需加上專案名稱;若為以 OC編寫,則放入 Class Name,https://developers.google.com/admob/ios/custom-events/setup#create)
#: [[檔案: IOS mediation setup.png |900px]]
#: [[檔案: IOS mediation setup 2.png |900px]]


== <b>實作方式</b> ==
== <b>實作方式</b> ==
<source>
<source>
import Foundation
import GoogleMobileAds
import TAMediaAdsFramework
class TADCustomEvent: NSObject, GADMediationAdapter {
class TADCustomEvent: NSObject, GADMediationAdapter {
     private var customEventNative: TADCustomEventNative?
     private var customEventNative: TADCustomEventNative?
     private var customEventBanner: TADCustomEventBanner?
     private var customEventBanner: TADCustomEventBanner?
     private var customEventInterstitial: TADCustomEventInterstitial?
     private var customEventInterstitial: TADCustomEventInterstitial?
 
   
     override required init() {
     override required init() {
         super.init()
         super.init()
     }
     }
 
   
     deinit {
     deinit {
         print("TADCustomEvent deinit")
         print("TADCustomEvent deinit")
行 27: 行 23:
      
      
     static func adapterVersion() -> GADVersionNumber {
     static func adapterVersion() -> GADVersionNumber {
         return GADVersionNumber(majorVersion: 2, minorVersion: 0, patchVersion: 0)
         return GADVersionNumber(majorVersion: 1, minorVersion: 0, patchVersion: 0)
     }
     }
      
      
行 62: 行 58:
     }
     }
}
}
</source>
</source>
[[SDK8 Google AdMob Mediation|回 AdMob Mediation]]

於 2023年4月7日 (五) 09:56 的最新修訂

簡介

首先將 AdMob 和 TAMedia SDK 整合至專案中,AdMob SDK可以在這裡下載(https://developers.google.com/mobile-ads-sdk/download?#downloadios)
接著在 AdMob Mediation 新增 Custom Event,新增 Custom Event 的詳細說明可以參考 (https://developers.google.com/admob/ios/custom-events/setup)
AdMob 將透過此客製化 class 向 TAmedia 請求廣告取得 Banner, Interstitial 及 Native 廣告。
在專案中加入與 Custom Event 對應的 Class,其中 Custom Event 的 Class Name 需要和專案新增的 Class Name 保持一致 例如新增的 Class Name 為 TADCustomEvent,Custom Event 的 Class Name 則必須是 專案名稱.TADCustomEvent。(以 Swift 編寫的專案需加上專案名稱;若為以 OC編寫,則放入 Class Name,https://developers.google.com/admob/ios/custom-events/setup#create)

  1. IOS mediation setup 2.png

實作方式

class TADCustomEvent: NSObject, GADMediationAdapter {
    private var customEventNative: TADCustomEventNative?
    private var customEventBanner: TADCustomEventBanner?
    private var customEventInterstitial: TADCustomEventInterstitial?
    
    override required init() {
        super.init()
    }
    
    deinit {
        print("TADCustomEvent deinit")
    }
    
    static func adapterVersion() -> GADVersionNumber {
        return GADVersionNumber(majorVersion: 1, minorVersion: 0, patchVersion: 0)
    }
    
    static func adSDKVersion() -> GADVersionNumber {
        let version = TADMobileAds.getSDKVersion().components(separatedBy: ".")
        let major = Int(version[0]) ?? 0
        let minor = Int(version[1]) ?? 0
        let patch = Int(version[2]) ?? 0
        return GADVersionNumber(majorVersion: major, minorVersion: minor, patchVersion: patch)
    }
    
    static func networkExtrasClass() -> GADAdNetworkExtras.Type? {
        return nil
    }
    
    static func setUpWith(_ configuration: GADMediationServerConfiguration, completionHandler: @escaping GADMediationAdapterSetUpCompletionBlock) {
        TADMobileAds.config()
        completionHandler(nil)
    }
    
    func loadBanner(for adConfiguration: GADMediationBannerAdConfiguration, completionHandler: @escaping GADMediationBannerLoadCompletionHandler) {
        customEventBanner = TADCustomEventBanner()
        customEventBanner?.loadBanner(for: adConfiguration, completionHandler: completionHandler)
    }
    
    func loadInterstitial(for adConfiguration: GADMediationInterstitialAdConfiguration, completionHandler: @escaping GADMediationInterstitialLoadCompletionHandler) {
        customEventInterstitial = TADCustomEventInterstitial()
        customEventInterstitial?.loadInterstitial(for: adConfiguration, completionHandler: completionHandler)
    }
    
    func loadNativeAd(for adConfiguration: GADMediationNativeAdConfiguration, completionHandler: @escaping GADMediationNativeLoadCompletionHandler) {
        customEventNative = TADCustomEventNative()
        customEventNative?.loadNativeAd(for: adConfiguration, completionHandler: completionHandler)
    }
}

回 AdMob Mediation