Integrate App Open Ads

To integrate any ad format, you must first have completed the instructions in the basic integration article.

App Open ad is a type of mobile advertisement designed to appear when a user opens a mobile app. These ads are full-screen and are typically displayed in a transition moment, such as when an app is launched or brought to the foreground.

Create an App Open Ad

To integrate App Open ads in your iOS app:

  1. Import VungleAdsSDK and add an instance variable for VungleInterstitial in your ViewController.swift file (or ViewController.h file for Objective-c).

    SwiftObjective-C
    import UIKit
    import VungleAdsSDK
    
    
    class LOInterstitialViewController: UIViewController {
    private var interstitialAd: VungleInterstitial?
    
    
            
  2. Add the following code to your method where you want to prepare the VungleInterstitial instance. To create the VungleInterstitial, you will need a Placement ID with 'App Open' placement type on the dashboard.

    SwiftObjective-C
    self.interstitialAd = VungleInterstitial(placementId: )
    self.interstitialAd?.delegate = self
            

Note: You must set your ViewController (or any class that declares conformance to VungleInterstitialDelegate) to the delegate property of the VungleInterstitial instance (refer to the Register for Callbacks section below).

Load an App Open Ad

  1. Once you create the VungleInterstitial instance, you can load an ad by calling load().

    SwiftObjective-C
    self.interstitialAd = VungleInterstitial(placementId: )
    self.interstitialAd?.delegate = self
    self.interstitialAd?.load()
            
  2. Your ViewController (or any class that conforms to VungleInterstitialDelegate) will receive notification of load success or error through delegate callback methods (refer to the Register for Callbacks section below).

Play an App Open Ad

  1. Once the App Open ad is successfully loaded, you can display it by calling present(with: <YOUR_ViewController>).

    SwiftObjective-C
    self.interstitialAd?.present(with: )
            
  2. During the time the App Open ad is visible to the user, you can listen for ad lifecycle events through delegate callback methods (refer to the Register for Callbacks section below).

  3. The ad is closed when the user closes it. You do not need to add steps in your code to close it.

Register for Callbacks

To receive notifications for ad events, declare conformance to VungleInterstitialDelegate protocol and implement callback methods. Each of the callback methods is optional, so you only need to implement the methods you want.

SwiftObjective-C
extension LOInterstitialViewController: VungleInterstitialDelegate {
    // Ad load events
    func interstitialAdDidLoad(_ interstitial: VungleInterstitial) {
        print("interstitialAdDidLoad")
    }
    
    func interstitialAdDidFailToLoad(_ interstitial: VungleInterstitial, withError: NSError) {
        print("interstitialAdDidFailToLoad")
    }


    // Ad Lifecycle Events
    func interstitialAdWillPresent(_ interstitial: VungleInterstitial) {
        print("interstitialAdWillPresent")
    }
    
    func interstitialAdDidPresent(_ interstitial: VungleInterstitial) {
        print("interstitialAdDidPresent")
    }
    
    func interstitialAdDidFailToPresent(_ interstitial: VungleInterstitial, withError: NSError) {
        print("interstitialAdDidFailToPresent")
    }
    
    func interstitialAdDidTrackImpression(_ interstitial: VungleInterstitial) {
        print("interstitialAdDidTrackImpression")
    }
    
    func interstitialAdDidClick(_ interstitial: VungleInterstitial) {
        print("interstitialAdDidClick")
    }
    
    func interstitialAdWillLeaveApplication(_ interstitial: VungleInterstitial) {
        print("interstitialAdWillLeaveApplication")
    }
    
    func interstitialAdWillClose(_ interstitial: VungleInterstitial) {
        print("interstitialAdWillClose")
    }
    
    func interstitialAdDidClose(_ interstitial: VungleInterstitial) {
        print("interstitialAdDidClose")
    }
}
    

Test an App Open Ad

You can test an App Open ad in one of two ways: by setting your app status to Test Mode so that Vungle can deliver test ads to your app, or by adding a test device to your app so that Vungle can deliver test ads specifically to the test device. Follow the instructions in Test Your Integration: Test Mode and Test Devices.

Questions?

Need further assistance, feel free to reach out to us, we’re here to help!

Was this article helpful?