# Interstitial Ad

## Add Files for Interstitial Ad Integration

Add `CESplash2AD.h CESplash2AD.m` to your app's build target.

## Request Interstitial Ad

* Import `CESplash2AD.h` and adopt `CESplash2ADRequestDelegate` protocol in view controller's extension.

```objectivec
// MyViewController.m

#import "CESplash2AD.h"

@interface MyViewController() <CESplash2ADRequestDelegate>
```

* Create a CESplash2AD instance and keep its reference. Load ad with your CESplash2AD instance.

```objectivec
@interface MyViewController() <CESplash2ADRequestDelegate>
@property (nonatomic, strong) CECSplash2AD *splashAd;
@end
​
- (void) viewDidLoad()
{
    CERequestInfo *info = [CERequestInfo new];
    info.placement = @"PUT_YOUR_PLACEMENT_STRING_HERE·";
    info.timeout = 5;
    self.splashAD = [[CESplash2AD alloc] initWithVideoViewProfile:CEVideoViewProfileSplash2DefaultProfile];
    [self.splashAD loadAdAsyncWithInfo:info reqDelegate:self];
}
```

* Implement `splash2ADDidLoaded:splash2AD` to handle ad loaded event.

```objectivec
#pragma mark - CESplash2ADRequestDelegate
- (void)splash2ADDidLoaded:(CESplash2AD*)splash2AD
{
    UIViewController *topController = [UIApplication sharedApplication].keyWindow.rootViewController;
    while (topController.presentedViewController) {
        topController = topController.presentedViewController;
    }

    [splash2AD showFromViewController:topController animated:YES];
}
```

## Add `CESplashADEventDelegate` to get the ad event callback.

If you want to trace the click, impression, progress event, please implement `CESplashADEventDelegate` to handle it.

```objectivec
#pragma mark - CESplash2ADEventDelegate
/*!
 *  @brief protocol of CESplash2ADEventDelegate that can receive AD events
 */
@protocol CESplash2ADEventDelegate <NSObject>
@optional
/*!
 *  @brief callback while this splash2 ad is clicked by user
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADDidClick:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback while splash2 ad is about to log impression
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADWillTrackImpression:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback while this splash2 ad is video format and muted.
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADDidMute:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback while this splash2 ad is video format and unmuted.
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADDidUnmute:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback while this splash2 ad is video format and start playback.
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADDidVideoStart:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback while this splash2 ad is video format and playback to end.
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADDidVideoEnd:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback while this splash2 ad is video format and progress state.
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 *  @param totalDuration this video total duration time (ms)
 *  @param currentPosition this video current play back position time (ms)
 */
- (void) splash2ADDidVideoProgress:(nonnull CESplash2AD *)splash2AD
                          duration:(int)totalDuration
                          position:(int)currentPosition;

/*!
 *  @brief callback function while splash2 AD did display from screen
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADDidDisplayed:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback function while splash2 AD did dismiss from screen
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADDidDismiss:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback function while splash2 AD will display to screen
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADWillDisplay:(nonnull CESplash2AD *)splash2AD;

/*!
 *  @brief callback function while splash2 AD will dismiss from screen
 *
 *  @param splash2AD CESplash2AD instance that own this splash2 ad component
 */
- (void) splash2ADWillDismiss:(nonnull CESplash2AD *)splash2AD;
@end
```

### Please refer to [CESplash2AD](/crystalexpress-documentation-v3-x/ios-sdk/api-reference/cesplash2ad.md) for more information in detail.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://intowow.gitbook.io/crystalexpress-documentation-v3-x/ios-sdk/quickstart-guide/step-3.-choose-ad-format/interstitial-ad.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
