Skip to content

Commit

Permalink
feat: change data property type & use default banner view if none pro…
Browse files Browse the repository at this point in the history
…vided
  • Loading branch information
OlenaPostindustria committed Dec 10, 2024
1 parent dc68e27 commit e8004f8
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SampleRenderer: NSObject, PrebidMobilePluginRenderer {

public let name = "SampleRenderer"
public let version = "1.0.0"
public var data: [AnyHashable: Any]?
public var data: [String: Any]?

public func isSupportRendering(for format: PrebidMobile.AdFormat?) -> Bool {
[PrebidMobile.AdFormat.banner, PrebidMobile.AdFormat.video].contains(format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class SampleRenderer: NSObject, PrebidMobilePluginRenderer {

public let name = "SampleRenderer"
public let version = "1.0.0"
public var data: [AnyHashable: Any]?
public var data: [String: Any]?

public func isSupportRendering(for format: AdFormat?) -> Bool {
[AdFormat.banner, AdFormat.video].contains(format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
import UIKit

/// A protocol for the plugin renderer, defining the basic interface that any renderer should implement.
/// This protocol provides the ability to retrieve plugin details, support rendering formats, and manage event delegates.
/// This protocol provides the ability to retrieve plugin details, support rendering formats, and manage event delegates and
/// methods for creating custom banner view and insterstitial controller.
@objc
public protocol PrebidMobilePluginRenderer: AnyObject {

Expand All @@ -27,7 +28,7 @@ public protocol PrebidMobilePluginRenderer: AnyObject {
@objc var version: String { get }

/// The version of the plugin renderer.
@objc var data: [AnyHashable: Any]? { get }
@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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,14 @@ - (void)createPrebidAdWithBid:(Bid *)bid
adUnitConfig:(AdUnitConfig *)adUnitConfig
adObjectSaver:(void (^)(id))adObjectSaver
loadMethodInvoker:(void (^)(dispatch_block_t))loadMethodInvoker {

id<PrebidMobilePluginRenderer> renderer = [[PrebidMobilePluginRegister shared] getPluginForPreferredRendererWithBid:bid];
PBMLogInfo(@"Renderer: %@", renderer);

CGRect const displayFrame = CGRectMake(0, 0, bid.size.width, bid.size.height);

dispatch_async(dispatch_get_main_queue(), ^{
UIView <PrebidMobileDisplayViewProtocol> * newDisplayView = [renderer createBannerViewWith:displayFrame
bid:bid
adConfiguration:adUnitConfig
loadingDelegate:self
interactionDelegate:self.delegate];

if (!newDisplayView) {
PBMLogError(@"SDK couldn't retrieve an implementation of PrebidMobileDisplayViewManagerProtocol.");
return;
}
UIView <PrebidMobileDisplayViewProtocol> * displayView = [self createBannerViewWithBid:bid
adUnitConfig:adUnitConfig];

adObjectSaver(newDisplayView);
adObjectSaver(displayView);

loadMethodInvoker(^{
[newDisplayView loadAd];
[displayView loadAd];
});
});
}
Expand Down Expand Up @@ -118,4 +104,30 @@ - (void)failedWithError:(nullable NSError *)error {
[self.flowDelegate adLoader:self failedWithPrimarySDKError:error];
}

- (UIView<PrebidMobileDisplayViewProtocol> *)createBannerViewWithBid:(Bid *)bid adUnitConfig:(AdUnitConfig *)adUnitConfig {
id<PrebidMobilePluginRenderer> renderer = [[PrebidMobilePluginRegister shared] getPluginForPreferredRendererWithBid:bid];
PBMLogInfo(@"Renderer: %@", renderer);

CGRect const displayFrame = CGRectMake(0, 0, bid.size.width, bid.size.height);

UIView <PrebidMobileDisplayViewProtocol> * displayView = [renderer createBannerViewWith:displayFrame
bid:bid
adConfiguration:adUnitConfig
loadingDelegate:self
interactionDelegate:self.delegate];

if (displayView) {
return displayView;
}

PBMLogWarn(@"SDK couldn't retrieve an implementation of PrebidMobileDisplayViewManagerProtocol. SDK will use the default one.");

PrebidRenderer *defaultRenderer = [PrebidRenderer new];
return [defaultRenderer createBannerViewWith:displayFrame
bid:bid
adConfiguration:adUnitConfig
loadingDelegate:self
interactionDelegate:self.delegate];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,14 @@ - (void)createPrebidAdWithBid:(Bid *)bid
adUnitConfig:(AdUnitConfig *)adUnitConfig
adObjectSaver:(void (^)(id))adObjectSaver
loadMethodInvoker:(void (^)(dispatch_block_t))loadMethodInvoker {

id<PrebidMobilePluginRenderer> renderer = [[PrebidMobilePluginRegister shared] getPluginForPreferredRendererWithBid:bid];
PBMLogInfo(@"Renderer: %@", renderer);

id<PrebidMobileInterstitialControllerProtocol> controller = [renderer createInterstitialControllerWithBid:bid
adConfiguration:adUnitConfig
loadingDelegate:self
interactionDelegate:self.delegate];

if (!controller) {
PBMLogError(@"SDK couldn't retrieve an implementation of PrebidMobileInterstitialControllerProtocol.");
return;
}

adObjectSaver(controller);

loadMethodInvoker(^{
[controller loadAd];
dispatch_async(dispatch_get_main_queue(), ^{
id<PrebidMobileInterstitialControllerProtocol> controller = [self createInterstitialControllerWithBid:bid
adUnitConfig:adUnitConfig];
adObjectSaver(controller);

loadMethodInvoker(^{
[controller loadAd];
});
});
}

Expand Down Expand Up @@ -138,4 +128,27 @@ - (void)failedWithError:(nullable NSError *)error {
[self.flowDelegate adLoader:self failedWithPrimarySDKError:error];
}

- (id<PrebidMobileInterstitialControllerProtocol>)createInterstitialControllerWithBid:(Bid *)bid
adUnitConfig:(AdUnitConfig *)adUnitConfig {
id<PrebidMobilePluginRenderer> renderer = [[PrebidMobilePluginRegister shared] getPluginForPreferredRendererWithBid:bid];
PBMLogInfo(@"Renderer: %@", renderer);

id<PrebidMobileInterstitialControllerProtocol> controller = [renderer createInterstitialControllerWithBid:bid
adConfiguration:adUnitConfig
loadingDelegate:self
interactionDelegate:self.delegate];

if (controller) {
return controller;
}

PBMLogWarn(@"SDK couldn't retrieve an implementation of PrebidMobileInterstitialControllerProtocol. SDK will use the default one.");

PrebidRenderer *defaultRenderer = [PrebidRenderer new];
return [defaultRenderer createInterstitialControllerWithBid:bid
adConfiguration:adUnitConfig
loadingDelegate:self
interactionDelegate:self.delegate];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class PrebidRenderer: NSObject, PrebidMobilePluginRenderer {

public let name = "PrebidRenderer"
public let version = Prebid.shared.version
public var data: [AnyHashable: Any]?
public var data: [String: Any]?

public func isSupportRendering(for format: AdFormat?) -> Bool {
[AdFormat.banner, AdFormat.video].contains(format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@ class MockPrebidMobilePluginRenderer: PrebidMobilePluginRenderer {

let name: String
let version: String
var data: [AnyHashable: Any]?
var data: [String: Any]?
var formats: Set<AdFormat> = []

init(
name: String,
version: String,
data: [AnyHashable: Any]? = nil
) {
init(name: String, version: String, data: [String: Any]? = nil) {
self.name = name
self.version = version
self.data = data
Expand All @@ -48,4 +44,23 @@ class MockPrebidMobilePluginRenderer: PrebidMobilePluginRenderer {
json["data"] = data
return json
}

func createBannerView(
with frame: CGRect,
bid: Bid,
adConfiguration: AdUnitConfig,
loadingDelegate: any DisplayViewLoadingDelegate,
interactionDelegate: any DisplayViewInteractionDelegate
) -> (any UIView & PrebidMobileDisplayViewProtocol)? {
return nil
}

func createInterstitialController(
bid: Bid,
adConfiguration: AdUnitConfig,
loadingDelegate: any InterstitialControllerLoadingDelegate,
interactionDelegate: any InterstitialControllerInteractionDelegate
) -> (any PrebidMobileInterstitialControllerProtocol)? {
return nil
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,15 @@ class PluginRegisterTest: XCTestCase {
}

func testGetPluginForBidContainingSampleCustomRenderer() {
let bidResponse = Bid(
let bid = Bid(
bid: RawSampleCustomRendererBidFabricator.makeSampleCustomRendererBid(
rendererName: "MockPrebidMobilePluginRenderer",
rendererVersion: "1.0.0"
)
)

let pluginRenderer = prebidMobilePluginRegister.getPluginForPreferredRenderer(
bid: bidResponse,
isInterstitial: false
bid: bid
)

XCTAssertEqual(pluginRenderer.name, plugin.name)
Expand Down

0 comments on commit e8004f8

Please sign in to comment.