Get Started with the MoPub SDK for iOS
- High-Level Steps to Integrate
- Step 1. Download the MoPub iOS SDK
- Incorporate the MoPub iOS SDK
- Step 2. Integrate the MoPub iOS SDK into Your Project
- Step 3. Integrate Third-Party Ad Networks and Adapters
- Step 4. Proper App Transport Security (ATS) configuration
- Step 5. Configure Ad Units in Your App
- Legal Disclosure
Use these instructions to integrate the MoPub SDK with your iOS app. If you are upgrading to version 5.0.0 or higher of the SDK, refer to the SDK Initialization and GDPR sections for additional steps.
- iOS 8.0 or higher
- Xcode 9.0 or higher
High-Level Steps to Integrate
- Download the MoPub iOS SDK.
- Integrate the MoPub iOS SDK into your project.
- Integrate third-party networks and adapters.
- Optionally verify the viewability integration through your device logs.
- Proper App Transport Security (ATS) configuration.
- Configure ad units in your app.
If you have any questions, don’t hesitate to email us at email@example.com.
Step 1. Download the MoPub iOS SDK
Option 1. Zipped Source
The MoPub SDK is distributed as source code for you to include in your application. MoPub provides two prepackaged archives of source code:
MoPub Base SDK.zip includes everything you need to serve Marketplace HTML, MRAID, and Native MoPub advertisements. It excludes third-party ad networks.
MoPub Base SDK Excluding Native.zip includes everything you need to serve HTML and MRAID advertisements. It excludes third-party ad networks and native MoPub advertisements.
Option 2. Clone the Git Repository
You can either use the bundled zips to install the MoPub SDK, or you can clone the Git repository as follows:
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, drag in the contents of the
Option 3. CocoaPods
The MoPub SDK is available through CocoaPods, a popular dependency management system for Objective-C and Swift projects.
To download and integrate the MoPub SDK into your project using CocoaPods, add the following line to your project’s
Option 4. MoPub SDK Frameworks
Starting with SDK v5.5, we are distributing three versions of the
- Simulator: built with i386 and x86_64 architectures
- Device: built with armv7 and arm64 architectures
- Universal: includes simulator and device architectures
We recommend that you use the
universal framework during development and testing process; and use the
device framework when submitting to the app store.
Incorporate the MoPub iOS SDK
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.
Step 2. Integrate the MoPub iOS SDK into Your Project
MoPubSDKfolder into your Xcode application group (be sure to select the Copy items into destination group’s folder option).
Add the following frameworks to your project by clicking on your application’s target, then clicking Build Phases and expanding the Link Binary With Libraries group.
The MoPub Base SDK requires the following frameworks:
For Apps Using MRC, Tell the Compiler to Use ARC
For applications using Manual Reference Counting (MRC), you must tell the compiler to build the MoPub iOS SDK source files with ARC. This is easy to do and has no impact on your application:
- Click on your application’s target, then click Build Settings.
- Set the Weak References in Manual Retain Release setting to
- Click Build Phases and expand the Compile Sources group.
- Select all the MoPubSDK source files. (They will be grouped together near the end if you have recently dragged in the SDK.)
- Scroll down and double-click on the last file. A blank popup appears.
-fobjc-arcand press [Enter] to add the
-fobjc-arcflag to all the selected files.
Step 3. Integrate Third-Party Ad Networks and Adapters
Refer to this tutorial for the integration details.
To use the MoPub SDK in your Swift project, simply import
MoPubSDK/MoPub-Bridging-Header.h to your project and ensure that the Objective-C Bridging Header build setting under Swift Compiler - Code Generation has a path to the header.
Step 4. Proper App Transport Security (ATS) configuration
App Transport Security (ATS), introduced in iOS 9, is a default setting that requires apps to make network requests only via HTTPS. To ensure ads work properly the below ATS configuration is strongly recommended.
Use the following ATS key/value in your app’s
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> <key>NSAllowsArbitraryLoadsForMedia</key> <true/> <key>NSAllowsArbitraryLoadsInWebContent</key> <true/> </dict>
You can also edit
Info.plist directly in Xcode. Set the key’s boolean flag to
ATS Setting Justification
Publishers will have to provide justification during the App Store review process for setting any of these ATS keys to YES in any MoPub SDK version. Per Apple’s App Store Review for ATS documentation, loading web content from a variety of sources (for ads) is an acceptable justification.
Step 5. Configure Ad Units in Your App
Once you’ve completed the above steps, you can start displaying ads in your application by configuring the ad units as shown in the link below for your ad format:
MoPub SDK v4.16 and above integrates technology from our partners Integral Ad Science, Inc. (“IAS”) and Moat, Inc. (“Moat”) in order to support viewability measurement and other proprietary reporting that IAS and Moat provide to their advertiser and publisher clients. You have the option to remove or disable this technology by following the opt-out instructions.
Last updated May 22, 2019
TWITTER, MOPUB, and the Bird logo are trademarks of Twitter, Inc. or its affiliates. All third party logos and trademarks included are the property of their respective owners.
© 2019 MoPub (a division of Twitter, Inc.)