# 插屏广告

插屏广告属于全屏广告，它会覆盖整个应用界面，直到用户将其关闭。这些广告通常会在应用流程的自然过渡点进行展示。当展示插屏广告时，用户可以点击广告前往目标页面，也可以关闭广告回到主页面。

下面将介绍如何将插屏广告植入iOS应用。

## 前提条件

* 通读[入门指南](/copy-of-cn/jie-kou-wen-dang/ios/kai-shi/ru-men-zhi-nan.md)

## 务必使用测试广告进行测试

在构建和测试应用时，请确保使用的是测试广告，而不是实际投放的广告。否则，可能会导致您的账号被暂停使用。对于 iOS 插屏广告，使用下面的测试专用广告单元 ID：

```
63a573a507ebe
```

该测试广告单元 ID 已经过专门配置，可确保每个请求返回的都是测试广告。您可以在自己应用的编码、测试和调试过程中随意使用该测试广告单元 ID。需要注意的一点是，请务必在发布应用前用您的广告单元 ID 替换该测试广告单元 ID。

## 接入步骤

主要步骤如下：

1. 请求广告
2. 注册回调
3. 处理广告事件

### 请求广告

请求插屏广告通过 <mark style="color:blue;">\[Adx3InterstitialAd sharedManager]</mark> 中 loadAdWithPlacementID: 方法完成，loadAdWithPlacementID: 方法需要您的广告单元 ID，userId 可不传或者传入您的应用为用户设置的 userId，最后通过回调 completionHandler 告知您请求的结果，以下为代码示例：

{% 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 %}

### 注册回调

要监听请求结果的回调 ，您必须实现 Adx3AdLoadingDelegate

要监听展示插屏事件的相关方法，您必须实现 Adx3InterstitialDeleagte，由于 Adx3InterstitialDeleagte 继承自 Adx3AdLoadingDelegate，所以您只需继承 Adx3InterstitialDeleagte 即可。代码示例：

{% 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 %}

### 展示广告

插屏广告应在应用流程的合适时机进行展示，代码示例：

{% 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 %}


---

# 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://docs.adx3.io/copy-of-cn/jie-kou-wen-dang/ios/guang-gao-ge-shi/cha-ping-guang-gao.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.
