Get Started with Vungle - iOS SDK (Swift)

This guide will run through a quick integration of our iOS SDK into a basic sample application- using Swift! The source code referenced here is available on our public GitHub repository.

A few notes before you get started...

  • The Vungle iOS SDK only supports iOS 7+
  • The integration requires a Vungle account, so create one here if you don't have one handy.
  • If you haven't already done so, head over to our dashboard and add your app to your account. You need to do this so that you can get your App ID that you’ll be adding to your app with our SDK. It’s in red on your app’s page.
 

Now let's get started.  We'll need 7 steps to get up and running.

1. Add the Vungle Framework to your Xcode project

The Vungle iOS SDK isn't included in the sample code we've got linked, you'll have to download it from the Vungle dashboard.

Unzip it and copy VungleSDK.embeddedframework/ into your project directory. Then drag and drop it into Xcode (Frameworks) to have it linked to your project.

The VungleSDK.embeddedframework folder should be added as a group (yellow folder) and not as a reference (blue folder).

 

2.  Add Other Required Frameworks

The Vungle SDK require a few other native frameworks to be linked to your project, so click on your project and head to:

General > Linked Frameworks and Libraries

Many of these frameworks will already be included, as they are default for most Xcode projects, but be sure to add any of the following that are not already included:

  • AdSupport.framework
  • AudioToolbox.framework
  • AVFoundation.framework
  • CFNetwork.framework
  • CoreGraphics.framework
  • CoreMedia.framework
  • Foundation.framework
  • libz.dylib
  • libsqlite3.dylib
  • MediaPlayer.framework
  • QuartzCore.framework
  • StoreKit.framework
  • SystemConfiguration.framework
  • UIKit.framework
  • WebKit.framework                  Add this as an Optional dependency

It's also a good idea to check that the VungleSDK framework appears under Linked Frameworks and Libraries. If the previous drag & drop step didn't link it automatically, we can manually add it by clicking the '+' and then 'Add Other'. 

3. Add the-ObjC linker flag

This can be added by navigating to Build Settings and adding -ObjC to Other Linker Flags in the Linking section

4. Remove the iOS Status Bar

This isn’t a required step, but it is recommended, as keeping the status bar at bay ensures that Vungle's ad interaction and presentation perform smoothly. To remove the status bar, open up your Info.pList and add the key "View controller-based status bar appearance" and set it to "No".

5.  Add Application Transport Security Exception

Starting in iOS 9 (with builds made from Xcode 7), Application Transport Security requires all network traffic made from an app to be secured via HTTPS.  You can read more about it in our Preparing your App for iOS 9 guide.  We're on the way towards HTTPs for all traffic made from the Vungle SDK, but in the mean time you'll need to add an AllowsArbitraryLoads exception to your .plist to ensure the Vungle works correctly. 

You can do this by adding a new Dictionary entry to your app's Info.plist file called NSAppTransportSecurity, and then adding an entry to that dictionary with a key of NSAllowsArbitraryLoads and a value of YES.

 

6. Create a Bridging Header File

  • Create a new Objective C file in your project (File->New->File [Objective C for iOS]).
  • Xcode will ask if you'd like to create a bridging header file between Objective C and Swift. Go ahead and accept this prompt.

  • Delete the new Objective C file but retain the bridging header file ${YOURPROJ}-Bridging-Header.h.
  • In the Bridging header file, import Vungle by adding #import <VungleSDK/VungleSDK.h>

 

7. Add the code!

  • Initialize the SDK - It's important to initialize the SDK as soon as possible to ensure that an ad has been pre-cached in time for the user.  For our sample project (and our recommendation for all iOS projects), we'll add our initialization call to the didFinishLaunchingWithOptions method on our main AppDelegate.

    AppDelegate.swift : didFinishLaunchingWithOptions:

    var appID = "Your AppID Here"
    var sdk = VungleSDK.sharedSDK()
    // start vungle publisher library
    sdk.startWithAppId(appID)

 

  • Play Ads in your ViewControllers - With the SDK initialized previously in the AppDelegate's didFinishLaunchingWithOptions, we can present an ad to the user by simply adding the following code snippet to your top presenting ViewController

  • TopViewController.swift
    var sdk = VungleSDK.sharedSDK()
    sdk.playAd(self, error: nil)
    

    The NSError parameter will be updated to include any error information in the event that a problem occurred during ad presentation. 

 

Advanced Settings

 If you're interested in some of the more advanced details of the Vungle iOS SDK (customization, event listeners, etc) feel free to check out our advanced settings guide. The Swift sample app shows an example of our playAd options.

Have more questions? Submit a request

Comments