Skip to content

Commit

Permalink
feat: add plugin renderer cases to demo apps
Browse files Browse the repository at this point in the history
  • Loading branch information
OlenaPostindustria committed Dec 5, 2024
1 parent 2cff93c commit ed2a3df
Show file tree
Hide file tree
Showing 32 changed files with 1,360 additions and 32 deletions.
82 changes: 82 additions & 0 deletions Example/PrebidDemo/PrebidDemo.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright 2019-2022 Prebid.org, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "BannerBaseViewController.h"

@import PrebidMobile;

NS_ASSUME_NONNULL_BEGIN

@interface InAppDisplayBannerPluginRendererViewController : BannerBaseViewController <BannerViewDelegate>

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/* Copyright 2019-2022 Prebid.org, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "InAppDisplayBannerPluginRendererViewController.h"
#import "PrebidDemoMacros.h"
#import "SampleAdViewRenderer.h"

NSString * const storedImpDisplayBannerPluginRendererInApp = @"prebid-demo-display-banner-320-50-custom-ad-view-renderer";

@interface InAppDisplayBannerPluginRendererViewController ()

// Prebid
@property (nonatomic) BannerView * prebidBannerView;

@end

@implementation InAppDisplayBannerPluginRendererViewController

- (void)loadView {
[super loadView];

[self createAd];
}

- (void)createAd {
// 1. Create a plugin renderer
SampleAdViewRenderer * samplePluginRenderer = [SampleAdViewRenderer new];

// 2. Register the plugin renderer
[Prebid registerPluginRenderer:samplePluginRenderer];

// 3. Create a BannerView
self.prebidBannerView = [[BannerView alloc] initWithFrame:CGRectMake(0, 0, self.adSize.width, self.adSize.height)
configID:storedImpDisplayBannerPluginRendererInApp
adSize:self.adSize];

// 4. Configure the BannerView
self.prebidBannerView.delegate = self;
self.prebidBannerView.adFormat = AdFormat.banner;
self.prebidBannerView.videoParameters.placement = PBPlacement.InBanner;

// Add Prebid banner view to the app UI
[self.bannerView addSubview:self.prebidBannerView];

// 5. Load the banner ad
[self.prebidBannerView loadAd];
}

// MARK: - BannerViewDelegate

- (UIViewController *)bannerViewPresentationController {
return self;
}

- (void)bannerView:(BannerView *)bannerView didFailToReceiveAdWith:(NSError *)error {
PBMLogError(@"%@", error.localizedDescription);
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/* Copyright 2019-2022 Prebid.org, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "InterstitialBaseViewController.h"

@import PrebidMobile;

NS_ASSUME_NONNULL_BEGIN

@interface InAppDisplayInterstitialPluginRendererViewController : InterstitialBaseViewController <InterstitialAdUnitDelegate>

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* Copyright 2019-2022 Prebid.org, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#import "InAppDisplayInterstitialPluginRendererViewController.h"
#import "PrebidDemoMacros.h"
#import "SampleInterstitialRenderer.h"

NSString * const storedImpDisplayInterstitialPluginRendererInApp = @"prebid-demo-display-interstitial-320-480-custom-interstitial-renderer";

@interface InAppDisplayInterstitialPluginRendererViewController ()

// Prebid
@property (nonatomic) InterstitialRenderingAdUnit * renderingInterstitial;

@end

@implementation InAppDisplayInterstitialPluginRendererViewController

- (void)loadView {
[super loadView];

[self createAd];
}

- (void)createAd {
// 1. Create a plugin renderer
SampleInterstitialRenderer * samplePluginRenderer = [SampleInterstitialRenderer new];

// 2. Register the plugin renderer
[Prebid registerPluginRenderer:samplePluginRenderer];

// 3. Create a InterstitialRenderingAdUnit
self.renderingInterstitial = [[InterstitialRenderingAdUnit alloc] initWithConfigID:storedImpDisplayInterstitialPluginRendererInApp];

// 4. Configure the InterstitialRenderingAdUnit
self.renderingInterstitial.adFormats = [[NSSet alloc] initWithObjects:AdFormat.banner, nil];
self.renderingInterstitial.delegate = self;

// 5. Load the interstitial ad
[self.renderingInterstitial loadAd];
}

// MARK: - InterstitialAdUnitDelegate

- (void)interstitialDidReceiveAd:(InterstitialRenderingAdUnit *)interstitial {
[self.renderingInterstitial showFrom:self];
}

- (void)interstitial:(InterstitialRenderingAdUnit *)interstitial didFailToReceiveAdWithError:(NSError *)error {
PBMLogError(@"%@", error.localizedDescription);
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*   Copyright 2018-2024 Prebid.org, Inc.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

#import <UIKit/UIKit.h>
#import <WebKit/WebKit.h>

@import PrebidMobile;

NS_ASSUME_NONNULL_BEGIN

/// An example showcasing the implementation of the `PrebidMobileDisplayViewProtocol`.
/// A sample view that is used for rendering ads.
@interface SampleAdView : UIView <PrebidMobileDisplayViewProtocol>

@property (nonatomic, weak, nullable) id<DisplayViewInteractionDelegate> interactionDelegate;
@property (nonatomic, weak, nullable) id<DisplayViewLoadingDelegate> loadingDelegate;
@property (nonatomic, strong) Bid *bid;

- (void)loadAd;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*   Copyright 2018-2024 Prebid.org, Inc.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

#import "SampleAdView.h"

@interface SampleAdView ()

@property (nonatomic, strong) WKWebView *webView;
@property (nonatomic, strong) UILabel *customRendererLabel;

@end

@implementation SampleAdView

- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setupView];
}
return self;
}

- (instancetype)initWithCoder:(NSCoder *)coder {
self = [super initWithCoder:coder];
if (self) {
[self setupView];
}
return self;
}

- (void)setupView {
self.webView = [[WKWebView alloc] init];
self.webView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.webView];

self.customRendererLabel = [[UILabel alloc] init];
self.customRendererLabel.translatesAutoresizingMaskIntoConstraints = NO;
self.customRendererLabel.text = @"Custom Renderer";
self.customRendererLabel.textColor = [UIColor whiteColor];
self.customRendererLabel.font = [UIFont boldSystemFontOfSize:10];
self.customRendererLabel.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
self.customRendererLabel.textAlignment = NSTextAlignmentCenter;
self.customRendererLabel.layer.cornerRadius = 5;
self.customRendererLabel.layer.masksToBounds = YES;
self.customRendererLabel.numberOfLines = 0;
[self addSubview:self.customRendererLabel];

[NSLayoutConstraint activateConstraints:@[
[self.webView.topAnchor constraintEqualToAnchor:self.topAnchor],
[self.webView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
[self.webView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
[self.webView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],

[self.customRendererLabel.topAnchor constraintEqualToAnchor:self.topAnchor constant:5],
[self.customRendererLabel.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:10],
[self.customRendererLabel.heightAnchor constraintEqualToConstant:40],
[self.customRendererLabel.widthAnchor constraintEqualToConstant:50]
]];
}

- (void)loadAd {
dispatch_async(dispatch_get_main_queue(), ^{
if (self.bid.adm) {
[self.webView loadHTMLString:self.bid.adm baseURL:nil];
[self.loadingDelegate displayViewDidLoadAd:self];
} else {
NSString * errorMessage = @"Renderer did fail - there is no ADM in the response.";
NSError *error = [NSError errorWithDomain:@"SampleAdViewErrorDomain"
code:101
userInfo:@{NSLocalizedDescriptionKey: errorMessage}];

[self.loadingDelegate displayView:self didFailWithError:error];
}
});
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*   Copyright 2018-2024 Prebid.org, Inc.
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at
 http://www.apache.org/licenses/LICENSE-2.0
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 */

#import <UIKit/UIKit.h>
#import "SampleAdView.h"

@import PrebidMobile;

NS_ASSUME_NONNULL_BEGIN

/// A custom implementation of the ad view renderer.
@interface SampleAdViewRenderer : NSObject <PrebidMobileAdViewPluginRenderer>

- (instancetype)init;

@end

NS_ASSUME_NONNULL_END
Loading

0 comments on commit ed2a3df

Please sign in to comment.