# Interstital

Interstitial ads are full-screen ads that cover the interface of an app until closed by the user. They're typically displayed at natural transition points in the flow of an app, such as between activities or during the pause between levels in a game. When an app shows an interstitial ad, the user has the choice to either tap on the ad and continue to its destination or close it and return to the app.

This guide shows you how to integrate interstitial ads into an iOS app.

### Prerequisites <a href="#prerequisites" id="prerequisites"></a>

* Complete the [Getting Started Guide](https://docs.adx3.io/interface-documentation/ios/get-started/getting-started-guide).

### Always test with test ads <a href="#always_test_with_test_ads" id="always_test_with_test_ads"></a>

When building and testing your apps, make sure you use test ads rather than live, production ads. Failure to do so can lead to suspension of your account. The easiest way to load test ads is to use our dedicated test ad unit ID for app interstitial ads:

```
63a573a507ebe
```

It's been specially configured to return test ads for every request, and you're free to use it in your own apps while coding, testing, and debugging. Just make sure you replace it with your own ad unit ID before publishing your app.

### Implementation <a href="#implementation" id="implementation"></a>

The main steps to integrating interstitial ads are:

* Load an ad
* Register for callbacks
* Display the ad and handle the event

#### Load an ad

Loading an ad is accomplished using the static loadAdWithPlacementID: method on the  Adx3InterstitialAd class. The load method requires your ad unit ID, a userId object, and a completion handler which gets called when ad loading succeeds or fails. userId object can not be passed or your custom user identifier. The below example shows how to load an Adx3InterstitialAd in your ViewController class.

{% tabs %}
{% tab title="Swift" %}

```swift
import UIKit

class ViewController: UIViewController, Adx3InterstitialDeleagte {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        loadInterstitialAd()
        // Do any additional setup after loading the view.
    }
    
    func loadInterstitialAd() {
        Adx3InterstitialAd.sharedManager().load(withPlacementID: "Your Placement ID", userId: "", delegate: self) { isSuccess in
            
        }
    }

}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
#import "Adx3Framework/Adx3Ad.h"

@interface ViewController()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadInterstitialAd];
}

- (void)loadInterstitialAd {
    [[Adx3InterstitialAd sharedManager] loadAdWithPlacementID:@"Your Placement ID" userId:@"" delegate:self completionHandler:^(BOOL isReady) {
        
    }];
}

@end
```

{% endtab %}
{% endtabs %}

#### Register for callbacks

You should rely on the Adx3InterstitialDelegate (optional) to handle display events and request events. The following code shows how to implement the protocol:

{% tabs %}
{% tab title="Swift" %}

```swift
import UIKit

class ViewController: UIViewController, Adx3InterstitialDeleagte {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view.
    }
}

extension ViewController {
    
    func didFinishLoadingAD(withPlacementID placementID: String!) {
        print("----Interstitial AD Load Finish----")
    }
    
    func didFailToLoadAD(withPlacementID placementID: String!, error: Error!) {
        print("----\(error.debugDescription)----")
    }
    
    func interstitialDidShow(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidClick(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidClose(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidEndPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidStartPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
    
    }
    
    func interstitialFailedToShow(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
        
    }
    
    func interstitialDidFailToPlayVideo(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
        
    }
    
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
#import "Adx3Framework/Adx3Ad.h"

@interface ViewController() <Adx3InterstitialDeleagte>

@end

@implementation ViewController

@end

#pragma mark - Adx3AdLoadingDelegate

- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
    NSLog(@"---Interstitial AD Load Finish----");
}

- (void)didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
    NSLog(@"----%@----", error.description);
}

#pragma mark - Adx3InterstitialDeleagte

-(void)interstitialDidShowForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {

}

-(void)interstitialFailedToShowForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary*)extra {

}

-(void)interstitialDidStartPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {

}

-(void)interstitialDidEndPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {

}

-(void)interstitialDidFailToPlayVideoForPlacementID:(NSString*)placementID error:(NSError*)error extra:(NSDictionary*)extra {

}

-(void)interstitialDidCloseForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {

}

-(void)interstitialDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {

}
```

{% endtab %}
{% endtabs %}

#### Display the ad

Interstitials should be displayed during natural pauses in the flow of an app. Between levels of a game is a good example, or after the user completes a task. Here's an example of how to do this in one of the action methods in a `UIViewController`:

{% tabs %}
{% tab title="Swift" %}

```swift
func showInterstitialAd() {
    Adx3InterstitialAd.sharedManager().showInterstitial(in: self, delegate: self)
}
```

{% endtab %}

{% tab title="Objective-C" %}

```objectivec
- (void)showInterstitialAd {
    [[Adx3InterstitialAd sharedManager] showInterstitialInViewController:self delegate:self];
}
```

{% endtab %}
{% endtabs %}
