Code Integration for iOS

Get started with Prebid Mobile by creating a Prebid Server account.

Use Cocoapods?

Easily include the Prebid Mobile SDK for your primary ad server in your Podfile.

platform :ios, '8.0'

target 'MyAmazingApp' do 
    pod 'PrebidMobile'

Build framework from source

Build Prebid Mobile from source code. After cloning the repo, from the root directory run


to output the PrebidMobile.framework.

Ad Unit Setup for iOS

Register Prebid Mobile ad units as early as possible in the application’s lifecycle. Each ad unit has an adUnitId which is an arbitrary unique identifier of the developer’s choice.

We recommend doing this in the didFinishLaunchingWithOptions method in AppDelegate.m using the following steps as shown in the code sample below:

  1. Create the ad units with ad unit ids and add sizes for banner ad units
  2. Add a server side configuration for each ad unit to Prebid Server Adapter
  3. Set targeting parameters for the ad units (Optional)
  4. Register the ad units with the adapter to start bid fetching process

Embed the ad unit registration in a try-catch block to catch all the exceptions (if any) thrown by the SDK.

#import "PrebidMobile/PBBannerAdUnit.h"
#import "PrebidMobile/PBServerAdapter.h"
#import "PrebidMobile/PBTargetingParams.h"
#import "PrebidMobile/PrebidMobile.h"
[PBLogManager setPBLogLevel:PBLogLevelAll];
// 1. Create the ad units with ad unit ids and add sizes for banner ad units
PBBannerAdUnit *__nullable adUnit1 = [[PBBannerAdUnit alloc] initWithAdUnitIdentifier:@"YOUR-AD-UNIT-ID-HERE" andConfigId:@"YOUR-CONFIG-ID-HERE"];
[adUnit1 addSize:CGSizeMake(300, 250)];
// 2. Set targeting parameters for the ad units (Optional)
[[PBTargetingParams sharedInstance] setAge:25];
[[PBTargetingParams sharedInstance] setGender:PBTargetingParamsGenderFemale];
// 3. Register the ad units with Prebid Mobile to start bid fetching process
// The following two APIs are being deprecated
//[PrebidMobile registerAdUnits:@[adUnit1] withAccountId:@"YOUR-ACCOUNT-ID-HERE"];
//[PrebidMobile registerAdUnits:@[adUnit1, adUnit2] withAccountId:kAccountId andPrimaryAdServer:PBPrimaryAdServerDFP];
// Use this instead:
[PrebidMobile registerAdUnits:@[adUnit1, adUnit2]

Set bid keywords on ad object

Prebid Mobile continuously pre-caches creatives in the background, so that right before the ad unit makes an ad request from your network, your app can ask Prebid Mobile for a bid price and creative without waiting as shown in the code below.

// Set the prebid keywords immediately on your adObject
[PrebidMobile setBidKeywordsOnAdObject:YOUR-AD-VIEW withAdUnitId:@"YOUR-AD-UNIT-ID-HERE"];

Alternatively, if you want to set the bid keywords on your adObject shortly after registering ad units, you can wait for bids with a timeout using the API method below.

// Set the prebid keywords on your adObject, upon completion load the adObject's ad
[PrebidMobile setBidKeywordsOnAdObject:YOUR-AD-VIEW withAdUnitId:@"YOUR-AD-UNIT-ID-HERE" withTimeout:600 completionHandler:^{

Use the table below to see which ad objects are supported currently.

Primary Ad Server Ad Object Type Ad Object Load Method
DFP Banner DFPBannerView - (void)loadRequest:(GADRequest *)request
DFP Interstitial DFPInterstitial - (void)loadRequest:(GADRequest *)request
MoPub Banner MPAdView - (void)loadAd
MoPub Interstitial MPInterstitialAdController - (void)loadAd