125 lines
4.4 KiB
Swift
125 lines
4.4 KiB
Swift
//
|
|
// GuruIronSourceBannerAd.swift
|
|
// Pods
|
|
//
|
|
// Created by 250102 on 2025/5/7.
|
|
//
|
|
import IronSource
|
|
|
|
class GuruIronSourceBannerView : GuruBannerView {
|
|
func view() -> UIView {
|
|
return bannerAdView
|
|
}
|
|
|
|
func setPlacementName(placement: String) {
|
|
bannerAdView.setPlacementName(placement)
|
|
}
|
|
|
|
func onShow() {
|
|
bannerAdView.isHidden = false
|
|
bannerAdView.resumeAutoRefresh()
|
|
}
|
|
|
|
func onHide() {
|
|
bannerAdView.isHidden = true
|
|
bannerAdView.pauseAutoRefresh()
|
|
}
|
|
|
|
public var bannerAdView: LPMBannerAdView
|
|
|
|
public init(_ banner: LPMBannerAdView) {
|
|
self.bannerAdView = banner
|
|
}
|
|
}
|
|
|
|
class GuruIronSourceBannerAd : GuruBannerAd, LPMBannerAdViewDelegate, ISImpressionDataDelegate {
|
|
|
|
private let viewController: UIViewController
|
|
private let adConfig: AdConfig
|
|
private var bannerAdCoordinator: GuruBannerCoordinator<GuruIronSourceBannerView>?
|
|
private var bannerAd: LPMBannerAdView? { return bannerAdCoordinator?.bannerAd.bannerAdView }
|
|
private var contentView: UIView?
|
|
private var currentUid2Token: String = ""
|
|
|
|
private var contentId: Int {
|
|
return self.adConfig.engineId
|
|
}
|
|
|
|
private let impressionListenerRegistrar: GuruIronSourceImpressionDataListenerRegistrar?
|
|
|
|
public init(viewController: UIViewController, adConfig: AdConfig, impressionListenerRegistrar: GuruIronSourceImpressionDataListenerRegistrar? = nil) {
|
|
self.viewController = viewController
|
|
self.adConfig = adConfig
|
|
self.impressionListenerRegistrar = impressionListenerRegistrar
|
|
super.init(engineId: adConfig.engineId, adUnitId: adConfig.adUnitId, adPlatform: AdPlatform.ironSource)
|
|
}
|
|
|
|
override func load() -> Bool {
|
|
let bannerAd = LPMBannerAdView(adUnitId: adConfig.adUnitId)
|
|
bannerAd.loadAd(with: self.viewController)
|
|
bannerAd.setDelegate(self)
|
|
impressionListenerRegistrar?.unregister(listener: self)
|
|
impressionListenerRegistrar?.register(adUnitId: adUnitId, listener: self)
|
|
bannerAd.setAdSize(LPMAdSize.banner())
|
|
bannerAd.pauseAutoRefresh()
|
|
bannerAdCoordinator = GuruBannerCoordinator(viewController: viewController, bannerAd: GuruIronSourceBannerView(bannerAd), contentId: contentId)
|
|
return true
|
|
}
|
|
|
|
public override func show(_ request: BannerShowRequest? = nil) -> Bool {
|
|
return bannerAdCoordinator?.show() ?? false
|
|
}
|
|
|
|
public override func hide() -> Bool {
|
|
return bannerAdCoordinator?.hide() ?? false
|
|
}
|
|
|
|
override public func destroy() -> Bool {
|
|
bannerAd?.destroy()
|
|
let _ = bannerAdCoordinator?.destroy()
|
|
bannerAdCoordinator = nil
|
|
impressionListenerRegistrar?.unregister(listener: self)
|
|
return true
|
|
}
|
|
|
|
override public func updateOrientation(orientation: ScreenOrientation) -> Bool {
|
|
return bannerAdCoordinator?.updateOrientation(orientation: orientation) ?? false
|
|
}
|
|
|
|
func didLoadAd(with adInfo: LPMAdInfo) {
|
|
adLoaded(ad: IronSourceFusionAd(engineId: engineId, adType: adType, ad: adInfo))
|
|
}
|
|
|
|
func didFailToLoadAd(withAdUnitId adUnitId: String, error: any Error) {
|
|
adLoadFailed(loadFailedInfo: LoadFailedInfo(engineId: engineId, adPlatform: adPlatform, adType: adType, adUnitId: adUnitId, error: SwiftFusionError(error)))
|
|
}
|
|
|
|
func didClickAd(with adInfo: LPMAdInfo) {
|
|
adClicked(ad: IronSourceFusionAd(engineId: engineId, adType: adType, ad: adInfo))
|
|
}
|
|
|
|
func didExpandAd(with adInfo: LPMAdInfo) {
|
|
adBannerExpanded(ad: IronSourceFusionAd(engineId: engineId, adType: adType, ad: adInfo))
|
|
}
|
|
|
|
func didDisplayAd(with adInfo: LPMAdInfo) {
|
|
adDisplayed(ad: IronSourceFusionAd(engineId: engineId, adType: adType, ad: adInfo))
|
|
}
|
|
|
|
func didCollapseAd(with adInfo: LPMAdInfo) {
|
|
adBannerCollapsed(ad: IronSourceFusionAd(engineId: engineId, adType: adType, ad: adInfo))
|
|
}
|
|
|
|
func didFailToDisplayAd(with adInfo: LPMAdInfo, error: any Error) {
|
|
adDisplayFailed(ad: IronSourceFusionAd(engineId: engineId, adType: adType, ad: adInfo), error: SwiftFusionError(error))
|
|
}
|
|
|
|
func didLeaveApp(with adInfo: LPMAdInfo) {
|
|
|
|
}
|
|
|
|
func impressionDataDidSucceed(_ impressionData: ISImpressionData!) {
|
|
adRevenuePaid(ad: IronSourceImpressedFusionAd(engineId: engineId, adType: adType, impressionData: impressionData))
|
|
}
|
|
}
|