Get Started

iOS Getting Started


This document details the process of integrating the MoPub SDK into your mobile application. If you have any questions, don’t hesitate to email us at [email protected].

Here are the basic integration steps:

  1. Download the MoPub SDK
  2. Add the SDK to your Xcode project.
  3. Create and use a Banner or Interstitial ad.

Download the MoPub iOS SDK

The MoPub SDK is distributed as source code that you must include in your application. MoPub provides two prepackaged archives of source code:

MoPub Base SDK.zip

Includes everything you need to serve HTML, MRAID, and Native MoPub advertisements (includes Rewarded Video).

  • Third party ad networks are not included.  (See ‘Adding Third Party Ad Networks’ below if needing to use third party ad networks)

MoPub Base SDK Excluding Native.zip

Includes everything you need to serve HTML and MRAID MoPub advertisements (includes Rewarded Video).

  • Third party ad networks and Native MoPub advertisements are not included. (See ‘Adding Third Party Ad Networks’ below if needing to use third party ad networks)

Incorporate the MoPub iOS SDK

These instructions assume that you have downloaded one of the MoPub SDK zip archives.

1. Download and unzip the MoPub iOS SDK.
2. Drag the MoPubSDK folder into your Xcode application group (be sure to check the “Copy items into destination group’s folder” option).

http://raw.githubusercontent.com/wiki/mopub/mopub-ios-sdk/images/drag-sdk.jpg


http://raw.githubusercontent.com/wiki/mopub/mopub-ios-sdk/images/add-sdk.jpg

3. Add the following frameworks to your project. To do this, click on your application’s target, then click on Build Phases and expand the Link Binary With Libraries group.

The MoPub Base SDK requires the following frameworks:

`AdSupport.framework`
`CoreGraphics.framework`
`CoreLocation.framework`
`CoreTelephony.framework`
`Foundation.framework`
`MediaPlayer.framework`
`QuartzCore.framework`
`StoreKit.framework`
`SystemConfiguration.framework`
`UIKit.framework`
`WebKit.framework`

In addition, the third party networks require
`AudioToolbox.framework`
`AVFoundation.framework`
`iAd.framework`
`MessageUI.framework`
`MobileCoreServices.framework`
`PassKit.framework`
`Social.framework`

Of these, you can mark `WebKit.framework` as optional. This is necessary if you are targeting iOS versions below 8.0.

You should now be ready to implement ad units into your application.


App Transport Security Settings
For App Transport Security related settings, please see this document for more information.


Using the GitHub Repository Source Code

  • While the bundled zips are the preferred method to install the MoPub SDK you can, instead, clone the git repository:
    • git clone git://github.com/mopub/mopub-ios-sdk.git
  • The installation instructions are similar to the ones outlined above for the zip archives. To install the base SDK you must drag in the contents of the `MoPubSDK` folder.

Using CocoaPods

  • The MoPub SDK is available through Cocoapods, a popular dependency management system for Objective-C projects.
  • To download and incorporate the MoPub SDK into your project using Cocoapods, add the following line to your project’s podfile: pod ‘mopub-ios-sdk’
  • After running `pod install` (if you’re setting up Cocoapods for the first time) or `pod update` (if you’re adding MoPub to an existing Cocoapods project), your project will be ready to use the base MoPub SDK. Currently we only support subspecs Ad Colony and Chartboost.

Adding Third Party Ad Networks

  • Third party ad networks are supported via custom event adapters.
  • Prebuilt custom event adapters for supported ad networks can be found in the `AdNetworkSupport` folder.  (Please review: Supported Mediation Partners for details such as supported network SDK version)

To install a custom event you must:

  • Download the desired third party SDK and add the header files and static libraries to your project.  (Please review: Supported Mediation Partners for details such as supported network SDK version)
  • Add the desired custom event to your project. You do this by cloning the `mopub-ios-sdk` repo and dragging the custom event `.h` and `.m` files from the relevant SDK folder under `AdNetworkSupport`.
  • Most integrations have two custom events, one for Banner ads and one for Interstitial ads.

Passing Location and Keywords

You can pass keywords from your app to MoPub as a comma-separated list in the ad view and use your user’s location to send more targeted ads from the MoPub Marketplace and certain ad networks.

For iOS, please follow these instructions for passing location and keywords.

For Applications that use MRC

  • If your application uses Manual Reference Counting (MRC) you must tell the compiler to build the MoPub iOS SDK source files with ARC. This has no impact on your application and can be done relatively easily:
  • First, click on your application’s target, then click on Build Phases and expand the Compile Sources group. Now select all the MoPubSDK source files. These will be grouped together near the end if you have recently dragged the SDK in.
  • Once the files are selected scroll down and double click on the last file. You should see a blank popup appear. Enter `-fobjc-arc` and hit return. This should add the `-fobjc-arc` flag to all the selected files.