iOS MoPub Mediation Adapter supports all display.io Ad Units.
MoPub / display.io ad units mapping:
display.io | MoPub | ||
![]() |
Interscroller | Banner | |
![]() |
Interstitial | Full Screen | |
![]() |
Infeed |
Medium Rectangle | |
![]() |
Medium Rectangle | Medium Rectangle | |
![]() |
Banner | Banner | |
To set it up:
1. Add the adapter to your project
Download source and add required files from "Classes" to your project.
2. Use Getting started guide to setup MoPub SDK (SDK lower 5.13 is not supported).
3. Setup account according to Quick Start Guide and create an app.
4. Create New line item and setup ad units, where Class Name:
- DIOMopubInterstitialAdapter for Interstitial Ad Unit;
- DIOMopubBannerAdapter for Banner Ad Unit;
- DIOMopubMediumRectangleAdapter for Medium Rectangle Ad Unit;
- DIOMopubInfeedAdapter for Infeed Ad Unit;
- DIOMopubInterscrollerAdapter for Interscroller Ad Unit.
and Custom event data { "placementid": "<PLACEMENT_ID>"} where <PLACEMENT_ID> is taken from display.io apps page:
5. Set targeting for your apps:
6. Enable new created network in Segments section:
8. Initialize MoPub and DIO SDK in viewDidLoad in your main ViewController:
[[DIOController sharedInstance] initializeWithProperties:nil appId:@"1234" completionHandler:^{
// Ready to go
} errorHandler:^(NSError *error) {
// Something wrong happened
}];
MPMoPubConfiguration *sdkConfig = [[MPMoPubConfiguration alloc] initWithAdUnitIdForAppInitialization:interstitialUnitId];
sdkConfig.additionalNetworks = @[DIOAdapterConfiguration.class];
sdkConfig.loggingLevel = MPBLogLevelInfo;
[[MoPub sharedInstance] initializeSdkWithConfiguration:sdkConfig completion:^{
// Ready to go
}];
9. Use Interstitial tutorial to get Interstitial ads from MoPub.
10. Use the Banner tutorial to get Banner or Medium Rectangle ads from MoPub.
11. In order to get Infeed ads from MoPub - apply the following steps:
#import "TableViewController.h"
#import "MPAdView.h"
#import <DIOSDK/DIOController.h>
@interface TableViewController () <MPAdViewDelegate> {
BOOL loaded;
}
@property (nonatomic, strong) MPAdView *mpAdView;
@end
@implementation TableViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell1"];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell2"];
self.mpAdView = [[MPAdView alloc] initWithAdUnitId:infeedUnitId];
[self.mpAdView stopAutomaticallyRefreshingContents];
self.mpAdView.delegate = self;
[self.mpAdView loadAd];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[DIOController sharedInstance] finishAllAds];
}
- (void)adViewDidLoadAd:(MPAdView *)view adSize:(CGSize)adSize {
self.mpAdView = view;
[self placeDioViewCorrectlyIfApplicable];
loaded = YES;
[self.tableView reloadData];
}
- (void) placeDioViewCorrectlyIfApplicable {
if (self.mpAdView.subviews.count == 0) {
return;
}
UIView *dioView = self.mpAdView.subviews[0];
[self.mpAdView.leadingAnchor constraintEqualToAnchor:dioView.leadingAnchor].active = YES;
[self.mpAdView.trailingAnchor constraintEqualToAnchor:dioView.trailingAnchor].active = YES;
[self.mpAdView.topAnchor constraintEqualToAnchor:dioView.topAnchor].active = YES;
[self.mpAdView.bottomAnchor constraintEqualToAnchor:dioView.bottomAnchor].active = YES;
}
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 30;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 15) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell.contentView.subviews.count > 0) [cell.contentView.subviews[0] removeFromSuperview];
[cell.contentView addSubview:self.mpAdView];
self.mpAdView.translatesAutoresizingMaskIntoConstraints = NO;
[cell.contentView.leadingAnchor constraintEqualToAnchor:self.mpAdView.leadingAnchor].active = YES;
[cell.contentView.trailingAnchor constraintEqualToAnchor:self.mpAdView.trailingAnchor].active = YES;
[cell.contentView.topAnchor constraintEqualToAnchor:self.mpAdView.topAnchor].active = YES;
[cell.contentView.bottomAnchor constraintEqualToAnchor:self.mpAdView.bottomAnchor].active = YES;
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell2" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @"Simple Cell";
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 15) {
if (loaded) {
CGFloat ratio = 300 / 250.0;
if (CGRectGetHeight(self.tableView.frame) < CGRectGetWidth(self.tableView.frame)) {
return CGRectGetHeight(self.tableView.frame) / ratio;
} else {
return CGRectGetWidth(self.tableView.frame) / ratio;
}
} else {
return 0;
}
}
return UITableViewAutomaticDimension;
}
@end
12. In order to get Interscroller ads from MoPub - apply the following steps:
#import "InterscrollerViewController.h"
#import "MPAdView.h"
#import <DIOSDK/DIOController.h>
#import <DIOSDK/DIOInterscrollerView.h>
@interface InterscrollerViewController () <MPAdViewDelegate>
property (nonatomic, strong) MPAdView *mpAdView;
@end
@implementation InterscrollerViewController
static const int AD_POSITION = 20;
static const int TABLE_SIZE = 40;
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.translucent = NO;
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell1"];
[self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell2"];
self.mpAdView = [[MPAdView alloc] initWithAdUnitId:interscrollerUnitId];
[self.mpAdView stopAutomaticallyRefreshingContents];
self.mpAdView.delegate = self;
[self.mpAdView loadAd];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[DIOController sharedInstance] finishAllAds];
}
- (void)adViewDidLoadAd:(MPAdView *)view adSize:(CGSize)adSize {
self.mpAdView = view;
}
- (UIViewController *)viewControllerForPresentingModalView {
return self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return TABLE_SIZE;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == AD_POSITION) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell1" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
if (cell.contentView.subviews.count > 0) [cell.contentView.subviews[0] removeFromSuperview];
if (self.mpAdView.subviews.count != 0) {
[cell.contentView addSubview:self.mpAdView];
self.mpAdView.translatesAutoresizingMaskIntoConstraints = NO;
[cell.contentView.leadingAnchor constraintEqualToAnchor:self.mpAdView.leadingAnchor].active = YES;
[cell.contentView.trailingAnchor constraintEqualToAnchor:self.mpAdView.trailingAnchor].active = YES;
[cell.contentView.topAnchor constraintEqualToAnchor:self.mpAdView.topAnchor].active = YES;
[cell.contentView.bottomAnchor constraintEqualToAnchor:self.mpAdView.bottomAnchor].active = YES;
DIOInterscrollerView *dioView = self.mpAdView.subviews[0];
[dioView setConstraintForIndexPath:indexPath];
}
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell2" forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.text = @"Simple Cell";
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewAutomaticDimension;
}
@end
Important:
Please pay special attention to constraints for mpAdView in order to show InFeed correctly inside the cell.
In order to stop Infeed or Interscroller ad and release all the resources associated with it (for example when leaving the screen) call:
[[DIOController sharedInstance] finishAllAds];
Comments
0 comments
Please sign in to leave a comment.