This page will show you how to integrate Leadbolt ads in your iOS native app. Download the SDK and sample app. Make sure you can compile the sample app and see test ads.
Contents
- Before you begin
- Add Leadbolt SDK framework
- Add the required frameworks
- Add Bridging Header
- Configure App Transport Security (ATS) Settings
- Initialize Leadbolt SDK
- To Cache and Show a non-Rewarded Ad
- To Cache and Show a Rewarded Ad
- Test your Integration
- Troubleshooting
- Advanced Integration
- Checking Ad Availability
- Passing Additional Information
- Using Event Listeners
Before you begin
- Have you logged in to the Leadbolt Publisher Portal?
- Did you add an App in the portal?
- Ensure, you have downloaded the Leadbolt SDK and sample app from the link above
Add Leadbolt SDK framework
- Copy the downloaded AppTracker.framework file to your Xcode Project
Add the required frameworks
- Link the following frameworks in your Xcode Project. AdSupport.framework, AVFoundation.framework, CoreMedia.framework, CoreTelephony.framework, StoreKit.framework, SystemConfiguration.framework and libz.tbd
Add Bridging Header
- Add a new Header file in your app and name it Objective-CBridgingHeader.h.
- In the file, add the following lines of code:
12@import UIKit;#import <AppTracker/AppTracker.h>
- Under your App’s Build Settings, find the Objective-C Bridging Header setting and add the full path of the Objective-CBridgingHeader.h file in there.
Configure App Transport Security (ATS) Settings
- To ensure all available Leadbolt ads display correctly on apps running on iOS 9/10, please include these ATS settings by adding the following lines of code to your Apps Info.plist file:
1234567<key>NSAppTransportSecurity</key><dict><key>NSAllowsArbitraryLoads</key><true/><key>NSAllowsArbitraryLoadsInWebContent</key><true/></dict>
Initialize Leadbolt SDK
- In your Project’s
viewDidLoad method add the following line to initialize the Leadbolt SDK.
123456override func viewDidLoad() {super.viewDidLoad()// Initialize Leadbolt SDK with your api keyAppTracker.startSession(self.API_KEY, with: AppTrackerEnableAutoCache);}
To Cache and Show a non-Rewarded Ad
- To cache a non-Rewarded Ad
1AppTracker.loadModule(toCache: "inapp"); - To show a non-Rewarded Ad
1AppTracker.loadModule("inapp", viewController: self); - Please ensure that in your code, you do not call loadModule directly after loadModuleToCache. It will cause the SDK to fail and not display an Ad all together.
- For Advanced SDK options, including use of Event Listeners, click here.
To Cache and Show a Rewarded Ad
- To cache a Rewarded Ad
1AppTracker.loadModule(toCache: "reward"); - To show a Rewarded Ad
1AppTracker.loadModule("reward", viewController: self); - Please ensure that in your code, you do not call loadModule directly after loadModuleToCache. It will cause SDK to fail and not display the Rewarded Ad at all.
- To reward user, refer to the Advanced Integration on more information about Event Listeners and Rewarding Users
Test your Integration
- Run your Project on an iOS device.
- Ensure, test ads are displayed when the “loadModule” call is made in your App.
- Once test ads are seen on your device, go to your Leadbolt Portal and set your App to “Live”
- Once approved, you should see live ads in your App.

Congratulations! You have successfully integrated the Leadbolt SDK in your App
Troubleshooting
- Video and Interstitial Ads may not be available at all times in all countries. It is always best to test with your App in Test Mode in the Publisher Portal as Test Ads are generally always available.
- You should check your Publisher Portal and ensure the relevant section is visible under your App. Use the “Add Section” button to add if not available.
- You should check the SDK logs located in Device Logs (under Xcode -> Devices) and look for “AppTracker”.
- Always test the sample app provided to confirm any integration issues are SDK based.
- The SDK has been tested to be compatible on Xcode Verion 9.4
Advanced Integration
Checking Ad Availability
Leadbolt SDK provides additional ability to the developers to check before hand if an Ad is available before displaying it to create a better user-experience in your App. To check if a Network or Direct Deal Ad is available please use the code below:
1 2 3 4 5 |
if(AppTracker.isAdReady("inapp")) { // Ad is available to be displayed } else { // Ad not ready to be displayed yet } |
To check if a Rewarded Ad is available to be displayed, please use the code below:
1 2 3 4 5 |
if(AppTracker.isAdReady("reward")) { // Rewarded Ad is available to be displayed } else { // Rewarded Ad not ready to be displayed yet } |
Passing Additional Information
You can increase your App’s performance by optionally including the additional information below. This allows selected premium advertisers to display their Ads to your users. To pass this additional information, use the following methods BEFORE calling loadModuleToCache
1 2 3 4 5 |
AppTracker.setAgeRange("18-25"); // Allowed values for Age range are: "13-17", "18-25", "26-35", "36-45", "46+" AppTracker.setGender("Female"); // Allowed values for Gender are: "Male", "Female" |
Using Event Listeners
With Event listeners, you can closely follow the ad states throughout your App. Leadbolt SDK will trigger events at all important stages of the Ad life-cycle. To implement event listeners in your App, you must implement the AppModuleDelegate class.
Setup SDK to use Event Listeners
Before using any of the Event Listener methods, first implement the AppModuleDelegate protocol your ViewController class as follows:
1 |
class ViewController: UIViewController, AppModuleDelegate |
Now, set the AppModuleDelegate object in the viewDidLoad method BEFORE calling AppTracker.startSession() like so:
1 |
AppTracker.setAppModuleDelegate(self); |
Event Listener Methods
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
func onModuleLoaded(_ placement: String!) { // Ad loaded successfully // Add code here to pause game and/or all media including audio } func onModuleFailed(_ placement: String!, error: String!, cached iscached: Bool) { if(iscached) { // Ad failed to cache } else { // Ad failed to display } } func onModuleClosed(_ placement: String!, reward:Bool) { // Ad closed by user // Add code here to resume game and/or all media including audio if(reward) { print("Reward Triggered"); } } func onModuleClicked(_ placement: String!) { // Ad clicked by user } func onModuleCached(_ placement: String!) { // Ad cached successfully // Add code if not auto-recaching for when loadModuleModuleToCache is successful } |