// // GuruIronSourceAdsSdk.swift // Pods // // Created by 250102 on 2025/5/6. // import IronSource public class GuruIronSourceAdsSdk: GuruAdsSdk { private static var instance: GuruIronSourceAdsSdk? public var adPlatform: AdPlatform { return AdPlatform.ironSource } private var initialized = false private static var interstitialAds: [String: GuruInterstitialAd] = [:] private static var rewardedAds: [String: GuruRewardedAd] = [:] private static var bannerAds: [String: GuruBannerAd] = [:] private static var mrecAds: [String: GuruMRecAd] = [:] private func logDebug(_ message: String) { Logger.d(tag: "GuruIronSourceAdsSdk", message: message) } private func logInfo(_ message: String) { Logger.i(tag: "GuruIronSourceAdsSdk", message: message) } private func logWarn(_ message: String) { Logger.w(tag: "GuruIronSourceAdsSdk", message: message) } private func logError(_ message: String) { Logger.e(tag: "GuruIronSourceAdsSdk", message: message) } private let viewController: UIViewController private let impressionDataDispatcher = GuruIronSourceImpressionDataDispatcher() private init(viewController: UIViewController) { self.viewController = viewController } public static func obtain(viewController: UIViewController) -> GuruAdsSdk { if let existingInstance = instance { return existingInstance } let newInstance = GuruIronSourceAdsSdk(viewController: viewController) instance = newInstance return newInstance } public func initialize(adsProfile: AdsProfile) async -> Bool { guard !initialized else { logWarn("SDK already initialized! Ignoring.") return false } if(adsProfile.ironSourceSdkKey?.isEmpty != false) { logError("ironSourceSdkKey is empty, unable to initialize") return false; } initialized = true if(adsProfile.debugMode) { IronSource.setMetaDataWithKey("is_test_suite", value: "enable") ISIntegrationHelper.validateIntegration() } IronSource.add(impressionDataDispatcher) return await withCheckedContinuation(isolation: MainActor.shared) { continuation in let requestBuilder = LPMInitRequestBuilder(appKey: adsProfile.ironSourceSdkKey!) .withUserId(adsProfile.userId) let initRequest = requestBuilder.build() LevelPlay.initWith(initRequest) { config, error in if let error = error { self.logError("initialize failed, \(error)") continuation.resume(returning: false) } else { continuation.resume(returning: true) } } } } public func obtainInterstitialAd(adConfig: AdConfig) -> GuruInterstitialAd { if let existingAd = Self.interstitialAds[adConfig.cacheKey] { return existingAd } let newAd = GuruIronSourceInterstitialAd(viewController: viewController, adConfig: adConfig) Self.interstitialAds[adConfig.cacheKey] = newAd return newAd } public func obtainRewardedAd(adConfig: AdConfig) -> GuruRewardedAd { if let existingAd = Self.rewardedAds[adConfig.cacheKey] { return existingAd } let newAd = GuruIronSourceRewardedAd(viewController: viewController, adConfig: adConfig) Self.rewardedAds[adConfig.cacheKey] = newAd return newAd } public func obtainBannerAd(adConfig: AdConfig) -> GuruBannerAd { if let existingAd = Self.bannerAds[adConfig.cacheKey] { return existingAd } let newAd = GuruIronSourceBannerAd(viewController: viewController, adConfig: adConfig) Self.bannerAds[adConfig.cacheKey] = newAd return newAd } public func obtainMRecAd(adConfig: AdConfig) -> GuruMRecAd { if let existingAd = Self.mrecAds[adConfig.cacheKey] { return existingAd } let newAd = GuruIronSourceMRecAd(viewController: viewController, adConfig: adConfig) Self.mrecAds[adConfig.cacheKey] = newAd return newAd } public func processCrossAction(action: AdsCrossAction) -> Bool { return false } }