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:
- Import
VungleAdsSDK
and add an instance variable forVungleInterstitial
in yourViewController.swift
file (orViewController.h
file for Objective-c).
import UIKit import VungleAdsSDK class LOInterstitialViewController: UIViewController { private var interstitialAd: VungleInterstitial?
#import "LOInterstitialViewController.h" #import @interface LOInterstitialViewController () @property (nonatomic, strong) VungleInterstitial *interstitialAd; @end
- Add the following code to your method where you want to prepare the
VungleInterstitial
instance. To create theVungleInterstitial
, you will need a Placement ID with 'App Open' placement type on the dashboard.
self.interstitialAd = VungleInterstitial(placementId: ) self.interstitialAd?.delegate = self
self.interstitialAd = [[VungleInterstitial alloc] initWithPlacementId:]; 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
- Once you create the
VungleInterstitial
instance, you can load an ad by callingload()
.
self.interstitialAd = VungleInterstitial(placementId: ) self.interstitialAd?.delegate = self self.interstitialAd?.load()
self.interstitialAd = [[VungleInterstitial alloc] initWithPlacementId:]; self.interstitialAd.delegate = self; [self.interstitialAd load:nil];
- Your
ViewController
(or any class that conforms toVungleInterstitialDelegate
) 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
- Once the App Open ad is successfully loaded, you can display it by calling
present(with: <YOUR_ViewController>)
.
self.interstitialAd?.present(with: )
[self.interstitialAd presentWith:];
- 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).
- 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.
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")
}
}
#pragma mark - VungleInterstitial Delegate Methods
// Ad load events
- (void)interstitialAdDidLoad:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidLoad");
}
- (void)interstitialAdDidFailToLoad:(VungleInterstitial *)interstitial
withError:(NSError *)withError {
NSLog(@"interstitialAdDidFailToLoad");
}
// Ad Lifecycle Events
- (void)interstitialAdWillPresent:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdWillPresent");
}
- (void)interstitialAdDidPresent:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidPresent");
}
- (void)interstitialAdDidFailToPresent:(VungleInterstitial *)interstitial
withError:(NSError *)withError {
NSLog(@"interstitialAdDidFailToPresent");
}
- (void)interstitialAdDidTrackImpression:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidTrackImpression");
}
- (void)interstitialAdDidClick:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdDidClick");
}
- (void)interstitialAdWillLeaveApplication:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdWillLeaveApplication");
}
- (void)interstitialAdWillClose:(VungleInterstitial *)interstitial {
NSLog(@"interstitialAdWillClose");
}
- (void)interstitialAdDidClose:(VungleInterstitial *)interstitial {
NSLog(@"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.