Skip to content

Commit 9035b49

Browse files
Mobile: Update plugin renderer section (prebid#5752)
* Update plugin renderer section * Update pbm-plugin-renderer.md * Spelling fix --------- Co-authored-by: Muki Seiler <muuki88@users.noreply.github.com>
1 parent 2949e78 commit 9035b49

1 file changed

Lines changed: 122 additions & 39 deletions

File tree

prebid-mobile/pbm-api/ios/pbm-plugin-renderer.md

Lines changed: 122 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -43,34 +43,117 @@ Please notice that all implementation on mobile related to the Plugin Renderer s
4343

4444
___
4545

46-
#### Create your implementation from the interface PrebidMobilePluginRenderer
46+
#### Create your implementation of the `PrebidMobilePluginRenderer`
47+
48+
The `PrebidMobilePluginRenderer` protocol is designed to provide a standardized way for developers to implement custom ad rendering solutions within the Prebid Mobile framework. It provides a unified interface for managing ad rendering, event handling, and metadata integration.
49+
50+
Below is the sample implementation of the renderer:
4751

4852
```swift
49-
public class SampleCustomRenderer: NSObject, PrebidMobilePluginRenderer {
50-
51-
public let name = "SampleCustomRenderer"
53+
public class SampleRenderer: NSObject, PrebidMobilePluginRenderer {
5254

55+
public let name = "SampleRenderer"
5356
public let version = "1.0.0"
57+
public var data: [String: Any]?
5458

55-
public var data: [AnyHashable: Any]? = nil
59+
/// This method creates an instance of `SampleAdView`, which is a custom view used to display the ad.
60+
public func createBannerView(
61+
with frame: CGRect,
62+
bid: Bid,
63+
adConfiguration: AdUnitConfig,
64+
loadingDelegate: DisplayViewLoadingDelegate,
65+
interactionDelegate: DisplayViewInteractionDelegate
66+
) -> (UIView & PrebidMobileDisplayViewProtocol)? {
67+
let adView = SampleAdView(frame: frame)
68+
69+
adView.interactionDelegate = interactionDelegate
70+
adView.loadingDelegate = loadingDelegate
71+
adView.bid = bid
72+
73+
return adView
74+
}
5675

57-
private var adViewManager: PBMAdViewManager?
76+
/// This method creates an instance of `SampleInterstitialController`,
77+
/// a custom controller used to display interstitial ads.
78+
public func createInterstitialController(
79+
bid: Bid,
80+
adConfiguration: AdUnitConfig,
81+
loadingDelegate: InterstitialControllerLoadingDelegate,
82+
interactionDelegate: InterstitialControllerInteractionDelegate
83+
) -> PrebidMobileInterstitialControllerProtocol? {
84+
let interstitialController = SampleInterstitialController()
85+
86+
interstitialController.loadingDelegate = loadingDelegate
87+
interstitialController.interactionDelegate = interactionDelegate
88+
interstitialController.bid = bid
89+
90+
return interstitialController
91+
}
92+
}
93+
94+
class SampleAdView: UIView, PrebidMobileDisplayViewProtocol {
5895

59-
public func isSupportRendering(for format: AdFormat?) -> Bool {}
60-
61-
public func setupBid(_ bid: Bid, adConfiguration: AdUnitConfig, connection: PrebidServerConnectionProtocol) {}
96+
weak var interactionDelegate: DisplayViewInteractionDelegate?
97+
weak var loadingDelegate: DisplayViewLoadingDelegate?
6298

63-
public func createBannerAdView(with frame: CGRect, bid: Bid, adConfiguration: AdUnitConfig,
64-
connection: PrebidServerConnectionProtocol, adViewDelegate: (any PBMAdViewDelegate)?) {
65-
// TODO "Handle bid response as you want and display your banner ad"
66-
}
99+
var bid: Bid?
67100

68-
public func createInterstitialController(bid: Bid, adConfiguration: AdUnitConfig, connection: PrebidServerConnectionProtocol,
69-
adViewManagerDelegate adViewDelegate: InterstitialController?, videoControlsConfig: VideoControlsConfiguration?) {
70-
// TODO "Handle bid response as you want and display your interstitial ad"
101+
// ...
102+
// Setup view
103+
// ...
104+
105+
func loadAd() {
106+
DispatchQueue.main.async {
107+
if let adm = self.bid?.adm {
108+
self.webView.loadHTMLString(adm, baseURL: nil)
109+
self.loadingDelegate?.displayViewDidLoadAd(self)
110+
} else {
111+
self.loadingDelegate?.displayView(self, didFailWithError: SampleError.noAdm)
112+
}
113+
}
71114
}
72115
}
73116

117+
class SampleInterstitialController: NSObject, PrebidMobileInterstitialControllerProtocol {
118+
119+
weak var loadingDelegate: InterstitialControllerLoadingDelegate?
120+
weak var interactionDelegate: InterstitialControllerInteractionDelegate?
121+
122+
var bid: Bid?
123+
124+
// ...
125+
// Setup view
126+
// ...
127+
128+
func loadAd() {
129+
DispatchQueue.main.async {
130+
guard let adm = self.bid?.adm else {
131+
self.loadingDelegate?.interstitialController(self, didFailWithError: SampleError.noAdm)
132+
return
133+
}
134+
135+
self.webView.loadHTMLString(adm, baseURL: nil)
136+
self.loadingDelegate?.interstitialControllerDidLoadAd(self)
137+
}
138+
}
139+
140+
func show() {
141+
DispatchQueue.main.async {
142+
guard let presentingController = UIApplication.shared.topViewController else {
143+
self.loadingDelegate?.interstitialController(
144+
self,
145+
didFailWithError: SampleError.noAvailableController
146+
)
147+
return
148+
}
149+
150+
presentingController.present(
151+
self.interstitialViewController,
152+
animated: true
153+
)
154+
}
155+
}
156+
}
74157
```
75158

76159
#### Global Initialization of Plugin Renderer
@@ -86,7 +169,7 @@ import PrebidMobile
86169
class AppDelegate: UIResponder, UIApplicationDelegate {
87170

88171
var window: UIWindow?
89-
let sampleCustomRenderer = SampleCustomRenderer()
172+
let sampleCustomRenderer = SampleRenderer()
90173

91174
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
92175
// Initialize the Prebid SDK
@@ -113,13 +196,11 @@ func applicationWillTerminate(_ application: UIApplication) {
113196
If you need to handle plugin registration in a specific view or controller for more granular control, you can still register the Plugin Renderer at that level:
114197

115198
```swift
116-
class CustomRendererBannerController: NSObject, AdaptedController, PrebidConfigurableBannerController, BannerViewDelegate {
199+
class CustomRendererBannerController: UIViewController {
117200

118-
required init(rootController: AdapterViewController) {
201+
override init() {
119202
super.init()
120-
self.rootController = rootController
121203
Prebid.registerPluginRenderer(sampleCustomRenderer)
122-
setupAdapterController()
123204
}
124205

125206
deinit {
@@ -131,15 +212,15 @@ class CustomRendererBannerController: NSObject, AdaptedController, PrebidConfigu
131212
## Limitations
132213

133214
### Supported Ad Formats
134-
Currently the interface `PrebidMobilePluginRenderer` provide the ability to render `BANNER` and `INTERSTITIAL` only. The compability with more ad formats can be supported in future releases.
135215

136-
It is important to notice that the compliant formats you set on `isSupportRenderingFor` implementation are taken into account to add your Plugin Renderer to the bid request or not, according to the ad unit configuration that is bid requesting.
216+
Currently the interface `PrebidMobilePluginRenderer` provides the ability to render `BANNER` and `INTERSTITIAL` only. The compability with more ad formats can be supported in future releases.
137217

138218
### Original API
139219

140-
The Plugin Renderer feature does not work with [GAM Original API](/prebid-mobile/pbm-api/android/android-sdk-integration-gam-original-api.html) since the ad rendering does not happen in the Prebid SDK but externally. Despite that if you are using the regular GAM integration it will work fine.
220+
The Plugin Renderer feature does not work with [GAM Original API](/prebid-mobile/pbm-api/ios/ios-sdk-integration-gam-original-api.html) since the ad rendering does not happen in the Prebid SDK but externally. Despite that if you are using the regular GAM integration it will work fine.
141221

142222
## Ad Event Listeners
223+
143224
An optional dedicated generic ad event listener is offered in case of the existing event listeners are insufficient to keep your ad consumer fully aware of your ad lifecycle.
144225

145226
![Plugin Event Listener big picture](/assets/images/prebid-mobile/prebid-plugin-renderer-event-listeners.png)
@@ -165,26 +246,19 @@ ___
165246
// TODO on impressions
166247
}
167248
}
168-
169249
```
170250

171251
#### Handle your plugin event delegate on your Plugin Renderer
172252

173253
```swift
174-
public class SampleCustomRenderer: NSObject, PrebidMobilePluginRenderer {
254+
public class SampleRenderer: NSObject, PrebidMobilePluginRenderer {
175255

176256
// Store your listeners
177257
private var pluginEventDelegateMap = [String: SampleCustomRendererEventDelegate]()
178258

179-
public let name = "SampleCustomRenderer"
180-
259+
public let name = "SampleRenderer"
181260
public let version = "1.0.0"
182-
183261
public var data: [AnyHashable: Any]? = nil
184-
185-
private var adViewManager: PBMAdViewManager?
186-
187-
public func isSupportRendering(for format: AdFormat?) -> Bool {}
188262

189263
public func registerEventDelegate(pluginEventDelegate: any PluginEventDelegate, adUnitConfigFingerprint: String) {
190264
pluginEventDelegateMap[adUnitConfigFingerprint] = pluginEventDelegate as? SampleCustomRendererEventDelegate
@@ -193,15 +267,24 @@ public class SampleCustomRenderer: NSObject, PrebidMobilePluginRenderer {
193267
public func unregisterEventDelegate(pluginEventDelegate: any PluginEventDelegate, adUnitConfigFingerprint: String) {
194268
pluginEventDelegateMap.removeValue(forKey: adUnitConfigFingerprint)
195269
}
196-
197-
public func setupBid(_ bid: Bid, adConfiguration: AdUnitConfig, connection: PrebidServerConnectionProtocol) {}
198270

199-
public func createBannerAdView(with frame: CGRect, bid: Bid, adConfiguration: AdUnitConfig,
200-
connection: PrebidServerConnectionProtocol, adViewDelegate: (any PBMAdViewDelegate)?) {
271+
public func createAdView(
272+
with frame: CGRect,
273+
bid: Bid,
274+
adConfiguration: AdUnitConfig,
275+
loadingDelegate: DisplayViewLoadingDelegate,
276+
interactionDelegate: DisplayViewInteractionDelegate
277+
) -> (UIView & PrebidMobileDisplayViewProtocol)? {
278+
// .......
201279
}
202280

203-
public func createInterstitialController(bid: Bid, adConfiguration: AdUnitConfig, connection: PrebidServerConnectionProtocol,
204-
adViewManagerDelegate adViewDelegate: InterstitialController?, videoControlsConfig: VideoControlsConfiguration?) {
281+
public func createInterstitialController(
282+
bid: Bid,
283+
adConfiguration: AdUnitConfig,
284+
loadingDelegate: InterstitialControllerLoadingDelegate,
285+
interactionDelegate: InterstitialControllerInteractionDelegate
286+
) -> PrebidMobileInterstitialControllerProtocol? {
287+
// .......
205288
}
206289
}
207290
```

0 commit comments

Comments
 (0)