187 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			Swift
		
	
	
			
		
		
	
	
			187 lines
		
	
	
		
			6.1 KiB
		
	
	
	
		
			Swift
		
	
	
| // FusionAdsSdk.swift
 | |
| // Main entry point for the FusionAds iOS SDK
 | |
| // Corresponds to GuruAdsSdk.kt in Android implementation
 | |
| 
 | |
| import Foundation
 | |
| import UIKit
 | |
| import AppLovinSDK
 | |
| import DTBiOSSDK
 | |
| import GuruConsent
 | |
| import OpenWrapSDK
 | |
| import InMobiSDK
 | |
| import TradPlusAds
 | |
| import MobileFuseSDK
 | |
| import IronSource
 | |
| import GoogleMobileAds
 | |
| import ChartboostSDK
 | |
| import IASDKCore
 | |
| import InMobiAdapter
 | |
| import VungleAdsSDK
 | |
| import MTGSDK
 | |
| 
 | |
| 
 | |
| #if DEBUG
 | |
| extension FusionAdsSdk {
 | |
|     public static func registerExternalAdPlatformSdkMapping(
 | |
|         platform: AdPlatform,
 | |
|         initializer: @escaping GuruAdsInitializer
 | |
|     ) {
 | |
|         externalAdPlatformSdkMapping[platform] = initializer
 | |
|     }
 | |
| }
 | |
| #endif
 | |
| 
 | |
| public class FusionAdsSdk {
 | |
|     
 | |
|     private static let adPlatformSdkMapping: [AdPlatform:GuruAdsInitializer] = [
 | |
|         AdPlatform.max : GuruMaxAdsSdk.obtain,
 | |
|         AdPlatform.ironSource : GuruIronSourceAdsSdk.obtain,
 | |
|         AdPlatform.adMob : GuruAdMobAdsSdk.obtain
 | |
|     ]
 | |
|     
 | |
|     private static var externalAdPlatformSdkMapping: [AdPlatform:GuruAdsInitializer] = [:]
 | |
|     
 | |
|     private let adsEngineManager: AdsEngineManager;
 | |
|     private let viewController: UIViewController;
 | |
|     
 | |
|     public init(controller: UIViewController) {
 | |
|         viewController = controller
 | |
|         adsEngineManager = AdsEngineManager(viewController: viewController)
 | |
|     }
 | |
|     
 | |
|     // Initialize the SDK with configuration profile
 | |
|     public func initialize(adsProfile: AdsProfile, analyticsEventHandler: AnalyticsEventHandler? = nil) async -> Bool {
 | |
|         
 | |
|         let initializers = Self.externalAdPlatformSdkMapping.merging(Self.adPlatformSdkMapping) {
 | |
|             (current, _) in current
 | |
|         }
 | |
|         if(analyticsEventHandler != nil) {
 | |
|             AnalyticsEvents.shared.registerHandler(handler: analyticsEventHandler!)
 | |
|         }
 | |
|         for adPlatform in adsProfile.adPlatforms {
 | |
|             let initializer = initializers[adPlatform]
 | |
|             let sdk = initializer?(viewController)
 | |
|             if sdk != nil {
 | |
|                 await sdk!.initialize(adsProfile: adsProfile)
 | |
|                 adsEngineManager.addAdsSdk(sdk!)
 | |
|             }
 | |
|         }
 | |
|         return true;
 | |
|     }
 | |
|     
 | |
|     // Create interstitial ad engine
 | |
|     public func createInterstitialAdEngine(adEngineConfig: AdEngineConfig) -> InterstitialAdEngine? {
 | |
|         return adsEngineManager.createInterstitialAdEngine(adEngineConfig: adEngineConfig)
 | |
|     }
 | |
|     
 | |
|     // Create rewarded ad engine
 | |
|     public func createRewardedAdEngine(adEngineConfig: AdEngineConfig) -> RewardedAdEngine? {
 | |
|         return adsEngineManager.createRewardedAdEngine(adEngineConfig: adEngineConfig)
 | |
|     }
 | |
|     
 | |
|     // Create banner ad engine
 | |
|     public func createBannerAdEngine(adEngineConfig: AdEngineConfig) -> BannerAdEngine? {
 | |
|         return adsEngineManager.createBannerAdEngine(adEngineConfig: adEngineConfig)
 | |
|     }
 | |
|     
 | |
|     // Create mrec ad engine
 | |
|     public func createMRecAdEngine(adEngineConfig: AdEngineConfig) -> MRecAdEngine? {
 | |
|         return adsEngineManager.createMRecAdEngine(adEngineConfig: adEngineConfig)
 | |
|     }
 | |
|     
 | |
|     public func getInterstitialAdEngine(id: Int) -> InterstitialAdEngine? {
 | |
|         return adsEngineManager.getInterstitialAdEngine(id: id)
 | |
|     }
 | |
|     
 | |
|     public func getRewardedAdEngine(id: Int) -> RewardedAdEngine? {
 | |
|         return adsEngineManager.getRewardedAdEngine(id: id)
 | |
|     }
 | |
|     
 | |
|     public func getBannerAdEngine(id: Int) -> BannerAdEngine? {
 | |
|         return adsEngineManager.getBannerAdEngine(id: id)
 | |
|     }
 | |
|     
 | |
|     public func getMRecAdEngine(id: Int) -> MRecAdEngine? {
 | |
|         return adsEngineManager.getMRecAdEngine(id: id)
 | |
|     }
 | |
|     
 | |
|     public func openDebugger(adPlatform: AdPlatform) -> Bool {
 | |
|         if (adPlatform == AdPlatform.max) {
 | |
|             ALSdk.shared().showMediationDebugger()
 | |
|         } else if (adPlatform == AdPlatform.ironSource) {
 | |
|             IronSource.launchTestSuite(viewController)
 | |
|         } else if (adPlatform == AdPlatform.adMob) {
 | |
|             GADMobileAds.sharedInstance().presentAdInspector(from: viewController)
 | |
|         }
 | |
|         return true;
 | |
|     }
 | |
|     
 | |
|     public func isTablet() throws -> Bool {
 | |
|         return UIDevice.current.userInterfaceIdiom == .pad
 | |
|     }
 | |
|     
 | |
|     public func afterAcceptPrivacy() -> Bool {
 | |
|         ALPrivacySettings.setHasUserConsent(true)
 | |
|         
 | |
|         // ironsource
 | |
|         IronSource.setConsent(true)
 | |
|         
 | |
|         // chartboost
 | |
|         let dataUseConsent = CHBDataUseConsent.GDPR(CHBDataUseConsent.GDPR.Consent.nonBehavioral)
 | |
|         Chartboost.addDataUseConsent(dataUseConsent)
 | |
|         
 | |
|         // fyber
 | |
|         IASDKCore.sharedInstance().gdprConsent = IAGDPRConsentType.given
 | |
|         IASDKCore.sharedInstance().gdprConsentString = "myGdprConsentString"
 | |
|         
 | |
|         // inmobi
 | |
|         var consentObject = Dictionary<String, String>()
 | |
|         consentObject["gdpr"] = "1"
 | |
|         consentObject[IMCommonConstants.IM_GDPR_CONSENT_AVAILABLE] = "true"
 | |
|         GADMInMobiConsent.updateGDPRConsent(consentObject)
 | |
|         
 | |
|         // vungle
 | |
|         VunglePrivacySettings.setGDPRStatus(true)
 | |
|         VunglePrivacySettings.setGDPRMessageVersion("v1.0.0")
 | |
|         
 | |
|         // mintegral
 | |
|         MTGSDK.sharedInstance().consentStatus = true
 | |
| 
 | |
|         return true
 | |
|     }
 | |
|     
 | |
|     public func updateOrientation(orientation: ScreenOrientation) {
 | |
|         adsEngineManager.dispatchOrientationUpdate(orientation: orientation)
 | |
|     }
 | |
|     
 | |
|     public func updateUid2Token(uid2Token: String) {
 | |
|         if (AdsHelper.setUid2Token(uid2Token)) {
 | |
|            NSLog("setUid2Token: \(uid2Token) success!!!")
 | |
| 
 | |
|            // PubMatic UID2
 | |
|            var userId = POBExternalUserId(source: "uidapi.com", andId: uid2Token)
 | |
|            userId.atype = 1
 | |
|            OpenWrapSDK.addExternalUserId(userId)
 | |
| 
 | |
|            // Inmobi UID2
 | |
|            IMSdk.setPublisherProvidedUnifiedId(["uidapi.com": uid2Token])
 | |
| 
 | |
|            // TradPlus
 | |
|            TradPlus.sharedInstance().uid2Info = {
 | |
|                let info = TradPlusUID2Info()
 | |
|                info.uid2Token = uid2Token
 | |
|                return info
 | |
|            }()
 | |
| 
 | |
|            // MobileFuse
 | |
|            MobileFuseTargetingData.setExtendedUserId(uid2Token, forPartner: "uidapi.com")
 | |
|        }
 | |
|     }
 | |
|     
 | |
|     // for testing only
 | |
|     public func clearCachedEngines() {
 | |
|         adsEngineManager.clearCachedEngines()
 | |
|     }
 | |
| }
 | |
| 
 |