124 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Swift
		
	
	
		
		
			
		
	
	
			124 lines
		
	
	
		
			4.5 KiB
		
	
	
	
		
			Swift
		
	
	
|  | // GuruMaxInterstitialAd.swift | ||
|  | // Implementation for MAX interstitial ads | ||
|  | // Corresponds to GuruMaxInterstitialAd.kt in Android implementation | ||
|  | 
 | ||
|  | import Foundation | ||
|  | import UIKit | ||
|  | import AppLovinSDK | ||
|  | 
 | ||
|  | public class GuruMaxInterstitialAd: GuruInterstitialAd, MAAdDelegate, MAAdRevenueDelegate { | ||
|  |      | ||
|  |     private let viewController: UIViewController | ||
|  |     private let adConfig: AdConfig | ||
|  |     private var interstitialAd: MAInterstitialAd? | ||
|  |     private var isFirstLoad = true | ||
|  |      | ||
|  |     public init(viewController: UIViewController, adConfig: AdConfig) { | ||
|  |         self.viewController = viewController | ||
|  |         self.adConfig = adConfig | ||
|  |         super.init(engineId: adConfig.engineId, adUnitId: adConfig.adUnitId, adPlatform: AdPlatform.max) | ||
|  |     } | ||
|  |      | ||
|  |     public override func logDebug(_ message: String) { | ||
|  |         Logger.d(tag: "MaxInterstitialAd[\(adConfig.adUnitId)]", message: message) | ||
|  |     } | ||
|  |      | ||
|  |     public override func logWarn(_ message: String) { | ||
|  |         Logger.w(tag: "MaxInterstitialAd[\(adConfig.adUnitId)]", message: message) | ||
|  |     } | ||
|  |      | ||
|  |     public override func load() -> Bool { | ||
|  |         Logger.i(tag: "MaxInterstitialAd[\(adConfig.adUnitId)]", message: "starting load") | ||
|  |         destroy() | ||
|  |          | ||
|  |         interstitialAd = MAInterstitialAd(adUnitIdentifier: adConfig.adUnitId) | ||
|  |         interstitialAd?.delegate = self | ||
|  |         interstitialAd?.revenueDelegate = self | ||
|  |          | ||
|  |         // Set UID2 token if available | ||
|  |         if let uid2Token = AdsHelper.getUid2Token() { | ||
|  |             interstitialAd?.setExtraParameterForKey("uid2_token", value: uid2Token) | ||
|  |         } | ||
|  |         interstitialAd?.setExtraParameterForKey("disable_auto_retries", value: self.adConfig.requireDisableAutoRetries ? "true":"false") | ||
|  |          | ||
|  |         if let amazonSlotId = adConfig.adAmazonSlotId, !amazonSlotId.isEmpty, isFirstLoad { | ||
|  |             isFirstLoad = false | ||
|  |              | ||
|  |             // In a real implementation, you would load Amazon ads here | ||
|  |             logDebug("Would load Amazon interstitial ad with slot ID: \(amazonSlotId)") | ||
|  |              | ||
|  |             // Simulate direct load for now | ||
|  |             interstitialAd?.load() | ||
|  |         } else { | ||
|  |             logDebug("Loading interstitial ad \(adConfig.adUnitId)") | ||
|  |             interstitialAd?.load() | ||
|  |         } | ||
|  |          | ||
|  |         return true | ||
|  |     } | ||
|  |      | ||
|  |     public override func show(_ request: InterstitialShowRequest? = nil) -> Bool { | ||
|  |         guard let ad = interstitialAd, ad.isReady else { | ||
|  |             logDebug("Show result: false - ad not ready") | ||
|  |             return false | ||
|  |         } | ||
|  |         ad.show(forPlacement: request?.placement) | ||
|  |         logDebug("Show result: true") | ||
|  |         return true | ||
|  |     } | ||
|  |      | ||
|  |     public override func destroy() -> Bool { | ||
|  |         interstitialAd?.delegate = nil | ||
|  |         interstitialAd?.revenueDelegate = nil | ||
|  |         interstitialAd = nil | ||
|  |         return true | ||
|  |     } | ||
|  |      | ||
|  |     // MARK: - MAAdDelegate methods | ||
|  |      | ||
|  |     public func didLoad(_ ad: MAAd) { | ||
|  |         Logger.i(tag: "MaxInterstitialAd[\(adConfig.adUnitId)]", message: "loaded") | ||
|  |         listener?.onAdLoaded(ad: MaxFusionAd(engineId: engineId, adType: AdType.Interstitial, ad: ad)) | ||
|  |     } | ||
|  |      | ||
|  |     public func didFailToLoadAd(forAdUnitIdentifier adUnitIdentifier: String, withError error: MAError) { | ||
|  |         logError("load failed, \(error.code) - \(error.message)") | ||
|  |         let loadFailedInfo = LoadFailedInfo( | ||
|  |             engineId: engineId, | ||
|  |             adPlatform: AdPlatform.max, | ||
|  |             adType: AdType.Interstitial, | ||
|  |             adUnitId: adUnitIdentifier, | ||
|  |             error: MaxFusionError(error) | ||
|  |         ) | ||
|  |         listener?.onAdLoadFailed(loadFailedInfo: loadFailedInfo) | ||
|  |     } | ||
|  |      | ||
|  |     public func didDisplay(_ ad: MAAd) { | ||
|  |         logInfo("displayed") | ||
|  |         listener?.onAdDisplayed(ad: MaxFusionAd(engineId: engineId, adType: AdType.Interstitial, ad: ad)) | ||
|  |     } | ||
|  |      | ||
|  |     public func didHide(_ ad: MAAd) { | ||
|  |         listener?.onAdHidden(ad: MaxFusionAd(engineId: engineId, adType: AdType.Interstitial, ad: ad)) | ||
|  |     } | ||
|  |      | ||
|  |     public func didClick(_ ad: MAAd) { | ||
|  |         listener?.onAdClicked(ad: MaxFusionAd(engineId: engineId, adType: AdType.Interstitial, ad: ad)) | ||
|  |     } | ||
|  |      | ||
|  |     public func didFail(toDisplay ad: MAAd, withError error: MAError) { | ||
|  |         logError("displayed failed, \(error.code) - \(error.message)") | ||
|  |         listener?.onAdDisplayFailed( | ||
|  |             ad: MaxFusionAd(engineId: engineId, adType: AdType.Interstitial, ad: ad), | ||
|  |             error: MaxFusionError(error) | ||
|  |         ) | ||
|  |     } | ||
|  |      | ||
|  |     // MARK: - MAAdRevenueDelegate methods | ||
|  |      | ||
|  |     public func didPayRevenue(for ad: MAAd) { | ||
|  |         logInfo("revenue paid") | ||
|  |         listener?.onAdRevenuePaid(ad: MaxFusionAd(engineId: engineId, adType: AdType.Interstitial, ad: ad)) | ||
|  |     } | ||
|  | } |