From 3f2d806699b8312ffdbb506ec12f5c991aad9d18 Mon Sep 17 00:00:00 2001 From: Olena Stepaniuk Date: Tue, 10 Dec 2024 15:29:36 +0200 Subject: [PATCH] feat: remove isSupportRendering --- .../InApp/SampleRenderers/SampleRenderer.h | 2 +- .../InApp/SampleRenderers/SampleRenderer.m | 4 ---- .../SampleRenderers/SampleRenderer.swift | 6 +----- .../Renderers/SampleRenderer.swift | 4 ---- .../PrebidMobilePluginRegister.swift | 16 +-------------- .../PrebidMobilePluginRenderer.swift | 5 +---- .../GAM/AdLoading/PBMBannerAdLoader.m | 4 ++++ .../GAM/AdLoading/PBMInterstitialAdLoader.m | 4 ++++ .../PBMCacheRenderers/PrebidRenderer.swift | 4 ---- .../MockPrebidMobilePluginRenderer.swift | 10 ---------- .../Tests/Prebid/PluginRegisterTest.swift | 20 ------------------- 11 files changed, 12 insertions(+), 67 deletions(-) diff --git a/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.h b/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.h index 90922a159..754d39b99 100644 --- a/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.h +++ b/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.h @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN -/// A custom implementation of the ad view renderer. +/// A custom implementation of the renderer. @interface SampleRenderer : NSObject - (instancetype)init; diff --git a/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.m b/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.m index 5888717bc..d612efaab 100644 --- a/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.m +++ b/Example/PrebidDemo/PrebidDemoObjectiveC/Examples/InApp/SampleRenderers/SampleRenderer.m @@ -30,10 +30,6 @@ - (instancetype)init { return self; } -- (BOOL)isSupportRenderingFor:(AdFormat *)format { - return [@[AdFormat.banner, AdFormat.video] containsObject:format]; -} - - (UIView * _Nullable)createBannerViewWith:(CGRect)frame bid:(Bid * _Nonnull)bid adConfiguration:(AdUnitConfig * _Nonnull)adConfiguration diff --git a/Example/PrebidDemo/PrebidDemoSwift/Examples/In-App/SampleRenderers/SampleRenderer.swift b/Example/PrebidDemo/PrebidDemoSwift/Examples/In-App/SampleRenderers/SampleRenderer.swift index bf07975d8..9c1d5a41a 100644 --- a/Example/PrebidDemo/PrebidDemoSwift/Examples/In-App/SampleRenderers/SampleRenderer.swift +++ b/Example/PrebidDemo/PrebidDemoSwift/Examples/In-App/SampleRenderers/SampleRenderer.swift @@ -16,17 +16,13 @@ import UIKit import PrebidMobile -/// A custom implementation of the ad view renderer. +/// A custom implementation of the renderer. public class SampleRenderer: NSObject, PrebidMobilePluginRenderer { public let name = "SampleRenderer" public let version = "1.0.0" public var data: [String: Any]? - public func isSupportRendering(for format: PrebidMobile.AdFormat?) -> Bool { - [PrebidMobile.AdFormat.banner, PrebidMobile.AdFormat.video].contains(format) - } - /// This method creates an instance of `SampleAdView`, which is a custom view used to display the ad. public func createBannerView( with frame: CGRect, diff --git a/InternalTestApp/PrebidMobileDemoRendering/ViewControllers/Adapters/Prebid/OpenX/CustomRenderer/Renderers/SampleRenderer.swift b/InternalTestApp/PrebidMobileDemoRendering/ViewControllers/Adapters/Prebid/OpenX/CustomRenderer/Renderers/SampleRenderer.swift index 79b1e6a7e..15f4378c6 100644 --- a/InternalTestApp/PrebidMobileDemoRendering/ViewControllers/Adapters/Prebid/OpenX/CustomRenderer/Renderers/SampleRenderer.swift +++ b/InternalTestApp/PrebidMobileDemoRendering/ViewControllers/Adapters/Prebid/OpenX/CustomRenderer/Renderers/SampleRenderer.swift @@ -22,10 +22,6 @@ public class SampleRenderer: NSObject, PrebidMobilePluginRenderer { public let version = "1.0.0" public var data: [String: Any]? - public func isSupportRendering(for format: AdFormat?) -> Bool { - [AdFormat.banner, AdFormat.video].contains(format) - } - public func createBannerView( with frame: CGRect, bid: Bid, diff --git a/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRegister.swift b/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRegister.swift index bc39c234e..e9c9ba765 100644 --- a/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRegister.swift +++ b/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRegister.swift @@ -98,27 +98,13 @@ public class PrebidMobilePluginRegister: NSObject { } } - /// Returns the list of available renderers for the given ad unit for RTB request - public func getRTBListOfRenderersFor(for adUnitConfig: AdUnitConfig) -> [PrebidMobilePluginRenderer] { - queue.sync { - plugins - .values - .filter { renderer in - adUnitConfig.adFormats.contains { format in - renderer.isSupportRendering(for: format) - } - } - } - } - /// Returns the registered renderer according to the preferred renderer name in the bid response. /// If no preferred renderer is found, it returns PrebidRenderer to perform default behavior. /// Once bid is win we want to resolve the best PluginRenderer candidate to render the ad. public func getPluginForPreferredRenderer(bid: Bid) -> PrebidMobilePluginRenderer { guard let preferredRendererName = bid.pluginRendererName, let preferredPlugin = getPluginRenderer(for: preferredRendererName), - preferredPlugin.version == bid.pluginRendererVersion, - preferredPlugin.isSupportRendering(for: bid.adFormat) + preferredPlugin.version == bid.pluginRendererVersion else { return defaultRenderer } diff --git a/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRenderer.swift b/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRenderer.swift index d5b7ddd75..65e708ad6 100644 --- a/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRenderer.swift +++ b/PrebidMobile/PrebidMobileRendering/PluginRenderer/PrebidMobilePluginRenderer.swift @@ -27,12 +27,9 @@ public protocol PrebidMobilePluginRenderer: AnyObject { /// The version of the plugin renderer. @objc var version: String { get } - /// The version of the plugin renderer. + /// Custom data to be included in the ORTB request. @objc var data: [String: Any]? { get } - /// Returns true only if the given ad unit could be renderer by the plugin. - @objc func isSupportRendering(for format: AdFormat?) -> Bool - /// Register a listener related to a specific ad unit config fingerprint in order to dispatch specific ad events. @objc optional func registerEventDelegate( pluginEventDelegate: PluginEventDelegate, diff --git a/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMBannerAdLoader.m b/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMBannerAdLoader.m index eb5478dc7..d617f8758 100644 --- a/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMBannerAdLoader.m +++ b/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMBannerAdLoader.m @@ -64,7 +64,11 @@ - (void)createPrebidAdWithBid:(Bid *)bid adUnitConfig:(AdUnitConfig *)adUnitConfig adObjectSaver:(void (^)(id))adObjectSaver loadMethodInvoker:(void (^)(dispatch_block_t))loadMethodInvoker { + @weakify(self); dispatch_async(dispatch_get_main_queue(), ^{ + @strongify(self); + if (!self) { return; } + UIView * displayView = [self createBannerViewWithBid:bid adUnitConfig:adUnitConfig]; diff --git a/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMInterstitialAdLoader.m b/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMInterstitialAdLoader.m index 65b5b688c..b18fa19f5 100644 --- a/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMInterstitialAdLoader.m +++ b/PrebidMobile/PrebidMobileRendering/Prebid/Integrations/GAM/AdLoading/PBMInterstitialAdLoader.m @@ -63,7 +63,11 @@ - (void)createPrebidAdWithBid:(Bid *)bid adUnitConfig:(AdUnitConfig *)adUnitConfig adObjectSaver:(void (^)(id))adObjectSaver loadMethodInvoker:(void (^)(dispatch_block_t))loadMethodInvoker { + @weakify(self); dispatch_async(dispatch_get_main_queue(), ^{ + @strongify(self); + if (!self) { return; } + id controller = [self createInterstitialControllerWithBid:bid adUnitConfig:adUnitConfig]; adObjectSaver(controller); diff --git a/PrebidMobile/PrebidMobileRendering/Prebid/PBMCacheRenderers/PrebidRenderer.swift b/PrebidMobile/PrebidMobileRendering/Prebid/PBMCacheRenderers/PrebidRenderer.swift index f73842492..576ac2797 100644 --- a/PrebidMobile/PrebidMobileRendering/Prebid/PBMCacheRenderers/PrebidRenderer.swift +++ b/PrebidMobile/PrebidMobileRendering/Prebid/PBMCacheRenderers/PrebidRenderer.swift @@ -21,10 +21,6 @@ public class PrebidRenderer: NSObject, PrebidMobilePluginRenderer { public let version = Prebid.shared.version public var data: [String: Any]? - public func isSupportRendering(for format: AdFormat?) -> Bool { - [AdFormat.banner, AdFormat.video].contains(format) - } - public func createBannerView( with frame: CGRect, bid: Bid, diff --git a/PrebidMobileTests/RenderingTests/Mocks/MockPrebidMobilePluginRenderer.swift b/PrebidMobileTests/RenderingTests/Mocks/MockPrebidMobilePluginRenderer.swift index 0a1110d65..9c7429d45 100644 --- a/PrebidMobileTests/RenderingTests/Mocks/MockPrebidMobilePluginRenderer.swift +++ b/PrebidMobileTests/RenderingTests/Mocks/MockPrebidMobilePluginRenderer.swift @@ -29,16 +29,6 @@ class MockPrebidMobilePluginRenderer: PrebidMobilePluginRenderer { self.data = data } - func isSupportRendering(for format: AdFormat?) -> Bool { - guard !formats.isEmpty else { return true } - - if let format { - return formats.contains(format) - } else { - return true - } - } - func jsonDictionary() -> [String: Any] { var json: [String: Any] = ["name": name, "version": version] json["data"] = data diff --git a/PrebidMobileTests/RenderingTests/Tests/Prebid/PluginRegisterTest.swift b/PrebidMobileTests/RenderingTests/Tests/Prebid/PluginRegisterTest.swift index 1fef8dfa1..ed01268e2 100644 --- a/PrebidMobileTests/RenderingTests/Tests/Prebid/PluginRegisterTest.swift +++ b/PrebidMobileTests/RenderingTests/Tests/Prebid/PluginRegisterTest.swift @@ -71,24 +71,4 @@ class PluginRegisterTest: XCTestCase { XCTAssertEqual(pluginRenderer.name, plugin.name) XCTAssertEqual(pluginRenderer.version, plugin.version) } - - func testGetRTBListOfRenderersFor() { - plugin.formats = [.banner, .video] - - let adUnitConfigBanner = AdUnitConfig( - configId: "configID", - size: CGSize(width: 300, height: 250) - ) - - var renderers = prebidMobilePluginRegister - .getRTBListOfRenderersFor(for: adUnitConfigBanner) - XCTAssertEqual(1, renderers.count) - - let adUnitConfigError = AdUnitConfig(configId: "configID") - adUnitConfigError.adFormats = [.native] - - renderers = prebidMobilePluginRegister - .getRTBListOfRenderersFor(for: adUnitConfigError) - XCTAssertEqual(0, renderers.count) - } }