This project contains sample source code that demonstrates how to integrate Infillion's interactive ad renderer in iOS. This document will step through the various pieces of code that make the integration work, so that the same basic ideas can be replicated in a real production app.
Infillion interactive ads include:
- TrueX ads - Interactive choice card experiences that allow users to skip an entire ad break by engaging with branded content
- IDVx ads - Interactive ads that start automatically and play inline with other ads in the break
This reference app covers the essential work. It assumes your app already has a working ad manager.
For a more detailed integration guide, please refer to: https://github.com/socialvibe/truex-mobile-integrations/
The Infillion Ad Renderer can be integrated via Swift Package Manager (recommended) or CocoaPods.
Add the TruexAdRenderer-iOS-Swift-Package repository to your project:
- In Xcode, go to File > Add Package Dependencies...
- Enter the repository URL:
https://github.com/socialvibe/TruexAdRenderer-iOS-Swift-Package - Select version
4.1.0or later
Alternatively, use the non-standard CocoaPods integration with the TrueX CocoaPods spec repository:
source 'https://github.com/socialvibe/cocoapod-specs.git'
target 'your-app' do
pod 'TruexAdRenderer-iOS', '4.1.0'
end
Ad break configuration is maintained in vmap.xml using the standard VMAP/VAST format. The app parses this VMAP to extract:
- Ad breaks with time offsets
- For each ad:
adSystem: ad type ("trueX", "IDVx", or "GDFP")VASTAdTagURI: wrapper URL for Infillion ads (TrueX and IDVx)mediaFile: URL for standard video adsduration: length of the ad
Wrapper Resolution: When an ad break starts, the app resolves all VAST wrapper URLs for Infillion ads to fetch fresh adParameters with valid session IDs. This ensures proper pixel firing for both TrueX and IDVx ads.
This reference app demonstrates both types of Infillion interactive ads:
TrueX ads present an interactive choice card where users can opt-in to engage with branded content. The user makes an active choice to interact with the ad. If the user completes the interaction, they earn an ad credit that skips the entire ad break, and the main video resumes immediately. If the user opts out or ignores the choice card, standard fallback ads play instead.
Key characteristics:
- Opt-in via choice card - User must actively choose to engage
- Skips entire ad break - Successful engagement bypasses all remaining ads in the pod
IDVx ads are interactive ads that start automatically without requiring opt-in. Unlike TrueX ads which require users to opt-in via a choice card, IDVx ads begin playing automatically. While no opt-in is required to start, users can interact with the ad content throughout its duration. IDVx ads play inline with other ads in the ad break. After an IDVx ad completes, the next ad in the sequence plays.
Key characteristics:
- Automatic start - No opt-in required, begins playing automatically
- Interactive throughout - Users can interact with ad content for its duration
- Plays inline - Completes and continues to next ad in the pod
Both TrueX and IDVx ads use the same configuration approach:
- VMAP contains
<Wrapper>elements with<VASTAdTagURI>pointing to the ad server - When an ad break starts, wrapper URLs are resolved to fetch
adParametersJSON - The
adParametersare passed toTruexAdRenderer.initWithVastConfigJson:
This unified approach ensures fresh session IDs for proper pixel tracking.
InfillionAdManager- Wrapper class that manages theTruexAdRendererfor both TrueX and IDVx adsInfillionAdType- Enum defining ad types (TrueX, IDVx, Regular) with helper functionsVideoPlayerViewController- Main view controller that handles video playback and ad break managementVmapParser- Utility class that parses VMAP XML and builds the ad break data structure
The following steps are a guideline for the Infillion Ad Renderer integration. This assumes you have setup the Ad Renderer dependency above. The starting/key points referenced in each step can be searched in the code for reference.
This sample app parses ad break configuration from a bundled VMAP file (vmap.xml). The important part is determining if a given ad is an Infillion interactive ad (TrueX or IDVx). This can vary depending on how ads are returned by the server. In this example, the AdSystem element in the VAST indicates the ad type.
The InfillionAdType helper functions (InfillionAdTypeFromString, IsInfillionAd) are used to identify and categorize ads.
When an Infillion ad is encountered, the InfillionAdManager is used to start the ad:
- Pause the main video playback
- Resolve VAST wrappers: Fetch the wrapper URL to get fresh
adParameterswith a valid session ID - Create an
InfillionAdManagerinstance and set its delegate - Call
startAdOnView:vastConfigUrl:adParameters:slotType:adType:withadParameters(for both TrueX and IDVx)
The InfillionAdManager internally creates a TruexAdRenderer using initWithVastConfigJson: for the unified configuration approach.
The InfillionAdManagerDelegate protocol provides callbacks for ad events:
-
infillionAdDidComplete:receivedCredit:- Called when the ad finishes- If
receivedCreditisYES(TrueX only): Skip all remaining ads in the break and resume content - If
receivedCreditisNO: Play the next ad in the sequence
- If
-
infillionAdDidStart:- Called when the ad begins playing -
infillionAdPopupWebsite:- Called when the user taps a link; pause the ad and show a web view
The VideoPlayerViewController manages the sequential playback of ads in a break:
- When an ad break starts,
playNextAdInBreakis called - For each ad, check the
adSystemto determine how to play it:- Infillion ads (TrueX/IDVx): Use
InfillionAdManager - Standard video ads (GDFP): Load the
mediaFileURL directly into the player
- Infillion ads (TrueX/IDVx): Use
- When an ad completes, increment the ad index and call
playNextAdInBreakagain - When all ads are done, call
resumeContentAfterAdsto restore the main video
Note: This reference app supports multiple interactive ads per ad break (TrueX, IDVx) with fallback ads, showing how different ad types can be sequenced in a single ad pod.
See the code for other ad events that are fired. Some events are for custom purposes if needed:
infillionAdDidOptIn:adId:- User opted into the TrueX engagementinfillionAdDidOptOut:- User opted out of the engagementinfillionAdSkipCardShown- Skip card was displayedinfillionAdUserCancel- User cancelled the engagementinfillionAdUserCancelStream- User wants to cancel the video stream
The infillionAdPopupWebsite: event is for handling user interactions that open external links. It is important to pause/resume the ad renderer when switching to another view, as shown in the code.