Use this article to easily integrate our SDK for iOS, whether you are using Objective-C or Swift.
Before You Begin
Requirements
- The integration requires a Liftoff account, so create an account if you haven’t already done so, and create a new iOS app in your account. Refer to the Add Your Apps and Placements section of our Using the Monetize Dashboard article to learn how to set up placements in the Monetize dashboard.
- Vungle iOS SDK v.6.12.3 supports Xcode 13 as recommended by Apple.
- For apps using Xcode 13, using Vungle SDK 6.10.3 or higher is required, as older SDKs do not support Xcode 13 for iOS 15 devices.
- Vungle iOS SDK v.6.12.3 is fully compatible with the latest iOS version (iOS 16 as of the release date) and supports 64-bit apps.
- Vungle iOS SDK v.6.12.3 supports applications that run on iOS 10 and higher. We do not recommend integrating the SDK for iOS versions lower than 10.0.
- Vungle iOS SDK v.6.12.3 supports SKAdNetwork 3.0 and AppTrackingTransparency using Xcode 13.0.
- For help answering the questions in Apple's App Store privacy questionnaire, refer to the data collection and use table in our Advanced Settings article.
Download the SDK
Download the latest Vungle SDK for iOS.
Reference: Sample App and Source Code
Feel free to refer to the sample app we have provided as you integrate: https://github.com/Vungle/iOS-SDK. The source code referenced here is available in our public GitHub repository:
Step 1. Add the Vungle Framework to Your Xcode Project
The Vungle SDK is available through Cocoapods. Add the following into your project’s podfile:
pod "VungleSDK-iOS", "6.12.3"
After that, a quick pod install run will update your project with the latest version of our iOS SDK. At this point you can skip down to "Implement ATT Framework and Integrate SKAdNetwork IDs".
Note: Starting with Vungle SDK 6.9.2+, Cocoapods requires a minimum version of 1.10.0 that provides pod support for XCFramework files. Testing was conducting using version 1.10.0+.
In addition to the -ObjC flag, be sure to verify $(inherited) is included inside Other Linked Flags in the Build Settings
1. Add the VungleSDK.framework to Your Project
Download Vungle SDK. If you are updating from a previous version of the Vungle SDK, first remove the VungleSDK.framework or VungleSDK.xcframework
directory completely before adding the new SDK.
Find the extracted files and drag the VungleSDK.framework or VungleSDK.xcframework
directory into Xcode under Frameworks. Be sure to add the VungleSDK.framework or VungleSDK.xcframework
folder as a group (yellow folder) and not as a reference (blue folder).
2. Add Other Required Frameworks
The Vungle SDK now ships with the build setting Link Frameworks Automatically set to YES; this means that you should no longer be required to link all the previously required frameworks and libraries (see below). With this update, you should only need to optionally link the following frameworks:
CoreFoundation.framework
Foundation.framework
StoreKit.framework
These previously required frameworks and libraries are included here so you can remove them if your project doesn’t reference any of them:
Support.framework
AudioToolbox.framework
AVFoundation.framework
CFNetwork.framework
CoreGraphics.framework
CoreMedia.framework
libz.dylib or libz.tbd
MediaPlayer.framework
QuartzCore.framework
StoreKit.framework
SystemConfiguration.framework
Note: Vungle SDK v.6.5.1+ does not support iOS 8 or lower. If you have iOS 7 as a deployment target, use Vungle iOS SDK v.4.1 or lower, and include these frameworks:
UIKit.framework
WebKit.framework
Foundation.framework
Confirm that the VungleSDK framework appears under Linked Frameworks and Libraries.
3. Add the “-ObjC” Linker Flag
Click on your project in Project Navigator and go to Build Settings → Linking → Other Linker Flags. Add -ObjC to Other Linker Flags.
Add SKAdNetwork IDs to Info.plist
Configure your app to participate in ad campaigns via the SKAdNetwork framework on iOS 14+. To do this, add the list of our approved partner IDs for advertising attribution to your Info.plist
file. Adding the Vungle SKAdnetwork ID and the IDs of all the DSPs to whom you want to sell indicates that your app wants to work with Vungle and accept bids from these buyers.
Refer to Apple’s documentation on configuring the Info.plist
properly for ad campaigns to be served. Refer also to the Xcode documentation for help on editing property lists.
Follow these steps to configure your app with SKAdNetworkIDs :
- Inside the Xcode Project navigator, open
Info.plist
file. - Click the add button (+) next to a key in a property list inside the
Info.plist
file in order to create a new property key. - Enter
SKAdNetworkItems
and select Array in the type column. - Add a dictionary item, then add a single String item inside the dictionary.
- For each String item, add
SKAdNetworkIdentifier
as the key and the ad network identifier as the value.
Vungle hosts the Vungle SKAdNetwork ID and the list of our buyers' SKAdNetwork IDs in both JSON and XML formats on our website. Note that our lists are updated periodically:
Step 2. Add Code
Initialize the SDK
Initialize the SDK as soon as your app starts. If you are using a cache-optimized placement, initializing now gives the SDK enough time to cache an ad for that placement. You will need the App ID to initialize the SDK. You can find the App ID in the Liftoff Monetize Dashboard.
- (BOOL)startWithAppId:(nonnull NSString *)appID error:(NSError **)error;
Sample code:
#import <VungleSDK/VungleSDK.h> ... NSError* error; NSString* appID = @"Your_AppID_Here"; VungleSDK* sdk = [VungleSDK sharedSDK]; if (![sdk startWithAppId:appID error:&error]) { if (error) { NSLog(@"Error encountered starting the VungleSDK: %@", error); } }
let appID = "Your_AppID_Here";
var placementIDsArray:Array<String> = ["<Your_PlacementID_1>", "<Your_PlacementID_2>", "<Your_PlacementID_3>"];
var sdk:VungleSDK = VungleSDK.shared()
do {
try sdk?.start(withAppId: kVungleTestAppID);
} catch let error as NSError {
print("Error while starting VungleSDK : \(error.domain)")
return;
}
Once the SDK is initialized successfully, the following callback method is called:
- (void)vungleSDKDidInitialize;
Swift Integration
Starting with iOS Vungle SDK v.6.10.1, a module map is being used to expose the header files in our framework. No bridging-header file is necessary for Swift integration.
In View Controller, import the VungleSDK module by adding the following:
import VungleSDK
VungleSDK v.6.9.2 and below Swift Integration: Create a Bridging Header File
- Create a new Objective-C file in your project (File →New →File [Objective-C File]).
- When Xcode asks if you want to create a bridging header file between Objective-C and Swift, accept the prompt.
- Delete the new Objective-C file
(${YOURPROJ}-Bridging-Header.m)
, but retain the bridging header file${YOURPROJ}-Bridging-Header.h
. - In the Bridging header file, import the Vungle SDK by adding the following:
#import <VungleSDK/VungleSDK.h>
Integrate Ad Formats
Complete your SDK integration for each ad format you plan to display in your app. Refer to our instructions for each ad format:
Further Customize Your Ads
Follow the instructions in our Advanced Settings article to fine-tune your app's integration with additional configuration options, such as GDPR, CCPA implementation, and many other settings.