> For the complete documentation index, see [llms.txt](https://docs.blueseasx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blueseasx.com/ios/interstitial-ads.md).

# Interstitial Ads

### **Step1. Load**

Before requesting ads, please ensure that the SDK has been initialized.

To request interstitial ads, declare a `BSXMediationInfo` object. This object should include the ad mediation platform, the mediation version, and the BlueSea Adapter version used when requesting the ads. If you are integrating BlueSea SDK through your own mediation platform, it is recommended to declare the `BSXMediationInfo` object and pass in the mediation information to facilitate monetization data management and channel monetization optimization. If you are integrating BlueSea SDK through third-party mediations like MAX, LevelPlay, etc., you can skip this step.

```
BSXMediationInfo *mediationInfo = [[BSXMediationInfo alloc] initWithMediationName:@"<in-house or mediation>" mediationVersion:@"<mediation version-name>" adapterVersion:@"<adapter-version-name>"];
```

* `<in house or mediation name>`: Pass the value as "in-house" or the specific mediation platform name.
* `<mediation-version-name>`: Pass the version number of the mediation SDK.
* `<adapter-version-code>`: Pass the version number of the adapter.

Call the `[loadInterstitialAdWithPlacementId:mediationInfo:delegate:]` method, pass the ad's Placement ID, and initiate the ad request:

```
[BlueSeaSDK loadInterstitialAdWithPlacementId:@"<BlueSea-pid>" mediationInfo:mediationInfo delegate:self];
@interface ViewController () <BSXInterstitialAdDelegate, BSXInterstitialAdLoadDelegate>
@end
@implementation ViewController () 
#pragma mark - BSXInterstitialAdLoadDelegate
- (void)didBSXInterstitialAdLoadError:(BSXAdError*)error {
    [self hideProgress];
    if (self.interstitialAd) {- (void)didBSXInterstitialAdLoadError:(BSXAdError*)error：
        [self.interstitialAd destroy];
    }
    self.interstitialAd = nil;
}
- (void)didBSXInterstitialAdLoaded:(BSXInterstitialAd *)ad {
    [self hideProgress];
    if (self.interstitialAd) {
        [self.interstitialAd destroy];
    }
    self.interstitialAd = ad;
    [self.interstitialAd setDelegate:self];
}
@end
```

`BSXInterstitialAdLoadDelegate` Callback:

* `- (void)didBSXInterstitialAdLoadError:(BSXAdError*)error`: Indicates that no ads were filled. This may be due to the advertiser not bidding or other issues. You can check the error code and message by using `BSXAdError.errorCode` and `BSXAdError.errorMsg`. For details on error codes, refer to [Test & Error Handling](/ios/test-and-error-handling.md)
* `- (void)didBSXInterstitialAdLoaded:(BSXInterstitialAd *)`: Indicates that the ad was successfully filled, and returns an instance of the `BSXInterstitialAd` object.

The following example shows how to fully load an interstitial ad in the `viewDidLoad` method of `ViewController`:

```
@interface ViewController () <BSXInterstitialAdDelegate, BSXInterstitialAdLoadDelegate>
@end
@implementation ViewController () 
- (void)viewDidLoad {
    [super viewDidLoad];
    BSXMediationInfo *mediationInfo = [[BSXMediationInfo alloc] initWithMediationName:@"<in-house or mediation>" mediationVersion:@"<mediation version-name>" adapterVersion:@"<adapter-version-name>"];
    [BlueSeaSDK loadInterstitialAdWithPlacementId:@"<BlueSea-pid>" mediationInfo:mediationInfo delegate:self];
}

#pragma mark - BSXInterstitialAdLoadDelegate
- (void)didBSXInterstitialAdLoadError:(BSXAdError*)error {
    if (self.interstitialAd) {
        [self.interstitialAd destroy];
    }
    self.interstitialAd = nil;
}
- (void)didBSXInterstitialAdLoaded:(BSXInterstitialAd *)ad {
    if (self.interstitialAd) {
        [self.interstitialAd destroy];
    }
    self.interstitialAd = ad;
    [self.interstitialAd setDelegate:self];
}
@end
```

### **Step2. Show**

After the `- (void)didBSXInterstitialAdLoaded:(BSXInterstitialAd *)ad` callback, register the ad listener using the `BSXInterstitialAdsetDelegate` method:

```
@interface ViewController () <BSXInterstitialAdDelegate, BSXInterstitialAdLoadDelegate>

@end
@implementation ViewController () 
- (void)viewDidLoad {
    [super viewDidLoad];
    BSXMediationInfo *mediationInfo = [[BSXMediationInfo alloc] initWithMediationName:@"<in-house or mediation>" mediationVersion:@"<mediation version-name>" adapterVersion:@"<adapter-version-name>"];
    [BlueSeaSDK loadInterstitialAdWithPlacementId:@"<BlueSea-pid>" mediationInfo:mediationInfo delegate:self];
}

#pragma mark - BSXInterstitialAdLoadDelegate
//ad load failed
- (void)didBSXInterstitialAdLoadError:(BSXAdError*)error {
    if (self.interstitialAd) {
        [self.interstitialAd destroy];
    }
    self.interstitialAd = nil;
}
//ad load succeeded
- (void)didBSXInterstitialAdLoaded:(BSXInterstitialAd *)ad {
    if (self.interstitialAd) {
        [self.interstitialAd destroy];
    }
    self.interstitialAd = ad;
    [self.interstitialAd setDelegate:self];
}

#pragma mark - BSXInterstitialAdDelegate
//ad display error
- (void)didBSXInterstitialAd:(BSXInterstitialAd *)ad displayError:(BSXAdError *)error {
    if (self.interstitialAd) {
        [self.interstitialAd destroy];
    }
    self.interstitialAd = nil;
}
//an ad impression occurred
- (void)didBSXInterstitialAdDisplayed:(BSXInterstitialAd *)ad {
    NSLog(@"InterstitialAd displayed.");
}
//the ad was clicked
- (void)didBSXInterstitialAdClicked:(BSXInterstitialAd *)ad {
    NSLog(@"InterstitialAd clicked.");
}
//the ad was opened
- (void)didBSXInterstitialAdOpened:(BSXInterstitialAd *)ad {
    NSLog(@"InterstitialAd opened.");
}
//the ad was closed
- (void)didBSXInterstitialAdClosed:(BSXInterstitialAd *)ad {
    NSLog(@"InterstitialAd closed.");
}
@end
```

Before displaying the ad, use the `[BSXInterstitialAd isExpired]` method to check if the ad has expired (the ad's validity period is typically 60 minutes). If the ad has expired, you can request a new one. If it has not expired, you can use the `[BSXInterstitialAd showWithController:]` method to display the interstitial ad:

```
[self.interstitialAd showWithController:self];
```

### **Step3. Destroy**

The SDK will automatically destroy the ad after detecting that the user has closed it.
