Integrating Banner Ads

Document created by david.simerly on Oct 20, 2017Last modified by david.simerly on Apr 3, 2018
Version 17Show Document
  • View in full screen mode

PubMatic SDKs 

PubMatic iOS SDK 

Getting Started

➤  Integrating Banner Ads

Banner ads are images or text that appear on a portion of an app's screen. The ad stays on screen as the user interacts with the app. The ad can auto refresh periodically.


You'll need to follow the instructions in Getting Started before proceeding with the following integration steps. You'll also find a useful example integration in SampleApp included in the SDK download bundle.



Once you've downloaded and installed the PubMatic iOS SDK, use the following sections to implement and configure banner ads:



Display Banner Ad

The steps below walk you through the banner ad implementation process:


Step 1: Import PMBannerAdview header file


#import "PMBannerAdview.h"


Import statements may differ for different integration methods.


Step 2: Setup Banner Ad View

A. Create an instance of PMBannerAdView.

B. Set the delegate property of the PMBannerAdView instance to PMBannerAdViewDelegate in your view controller.

C. Add the PMBannerAdView as a subview to your view.


@interface BannerAdViewController ()<PMBannerAdViewDelegate>
@property (nonatomic) PMBannerAdView * adView;

@implementation BannerAdViewController

- (void)viewDidLoad {

    [super viewDidLoad];
    self.adView = [[PMBannerAdView alloc] initWithFrame:<#CGRect#>];
    [self.adView setDelegate:self];
    [self.view addSubview:self.adView];


Step 3: Create a Banner Ad Request

After you have set up the PMBannerAdView, create an instance of PMBannerAdRequest:


PMBannerAdRequest * adRequest = [[PMBannerAdRequest alloc] initWithPublisherId:@"<#PUB_ID#>" siteId:@"<#SITE_ID#>" adId:@"<#AD_ID#>"];

// Required
adRequest.adSize = PMBANNER_SIZE_320x50;


Setting the adSize property is required and mandatory.



Step 4: Request the Ad

Now you're ready to request the ad from PubMatic:


// Make the ad request to PubMatic  
[self.adView loadRequest:adRequest];


Step 5: Receiving PMBannerAdViewDelegate Callbacks

PubMatic SDK provides PMBannerAdViewDelegate to receive ad event callbacks.


Make sure you set the delegate for the PMBannerAdView instance (step 2B above), before calling the loadRequest: method.


- (void)bannerAdViewDidRecieveAd:(PMBannerAdView *)adView{
    CGSize size = adView.getAdSize;
    // Use size instance to resize the Banner Ad view (by updating constraints or to frame appropriately for your implementation).

-(void)bannerAdView:(PMBannerAdView *)adView didFailToReceiveAdWithError:(PMError *)error{
    // Called when an ad fails to load.

// If UIViewController reference is not available, you do not need to implement this method.
- (UIViewController*)bannerAdViewPresentationController:(PMBannerAdView*)adView{
    return self;


See PubMatic SDK Error Codes for a detailed description of the PMError object used in the bannerAdView:didFailToReceiveAdWithError: callback.


To fully support all MRAID events please follow the steps in Rich Media (MRAID 2.0) Support.


Enable Auto Refresh

PubMatic iOS SDK provides the optional feature to auto refresh a banner ad after a specified interval. You can set the refresh interval in code using self.adView.updateInterval = <#value in secs#> before calling the loadRequest: method. Use an interval value within a range of 12 to 120 seconds.


// Refresh the ad every 15 seconds
self.adView.updateInterval = 15;
[self.adView loadRequest:adRequest];


Ad Refresh Behavior for Value of Update Intervals

Integer value ( i ) in secondsBanner Auto-refresh behavior
i <= 0Ad will not refresh
i > 0 & i <= 12Ad will refresh after every 12 seconds.
i > 12 & i <= 120Ad will refresh after every i seconds
i > 120Ad will refresh after every 120 seconds


Multisize Ad Support

You can specify multiple sizes in an ad request. Then SSP/Exchange serves the ad with the creative that best fits into those sizes and returns greater CPMs. This flexibility makes a greater number of campaigns/creatives eligible for the current impression, which can lead to increased fill rate.


adRequest.optionalAdSizes = @[[NSValue valueWithCGSize:PMBANNER_SIZE_320x50],[NSValue valueWithCGSize:PMBANNER_SIZE_300x50]]


Get the size of the creative if you need to write your own logic to resize the ad slot. For example:


- (void)bannerAdViewDidRecieveAd:(PMBannerAdView *)adView{
    CGSize size = adView.getAdSize;
    /* Use the size object to resize the banner ad view (by updating the constraints or
       frame as needed for your implementation).