# 开屏广告

本指南适用于植入开屏广告的发布商

开屏广告是一种特殊的广告格式，适合希望通过应用启动时加载广告的发布商。用户可以随时关闭开屏广告。以下是一个开屏广告示例：

【占位图】

<div align="left"><figure><img src="/files/jYDcW5uTZP00X3wnaG6b" alt=""><figcaption></figcaption></figure></div>

概括来讲，植入开屏广告需要执行的步骤如下：

1. 向您的应用首页添加方法，以加载并显示开屏广告
2. 处理展示回调

## 前提条件

* 按照[入门指南](/copy-of-cn/jie-kou-wen-dang/ios/kai-shi/ru-men-zhi-nan.md)的设置说明操作

务必用测试广告进行测试

在构建和测试应用时，请确保使用的是测试广告，而不是实际投放的广告。否则可能导致能的账号被暂停。对于开屏广告，加载测试广告最简便的方法就是使用下面的测试专用广告单元ID：

```
63a57390cf26c
```

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

#### 修改应用代理

开屏广告会在您的应用启动时展示。为确保用户打开您的应用时有广告可以展示，您需要引用随时可用的广告。

这意味着，在需要展示广告之前，您必须预加载一个开屏广告。这样一来，开屏广告就可以在应用下次启动时展示。

您可以在 AppDelegate.m 中添加请求开屏广告的方法：

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

```swift
func requestAppOpenAd() {
    //userId 
    Adx3FullScreenAd.sharedManager().load(withPlacementID: "Your Placement ID", userId: "", delegate: self)
}
```

{% endtab %}

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

```objectivec
- (void)requestAppOpenAd {
    //userId Optional
    [[Adx3FullScreenAd sharedManager] loadAdWithPlacementID:@"Your Placement ID" userId:@"" delegate:self];
}
```

{% endtab %}
{% endtabs %}

该方法会发起加载新的开屏广告请求，以便用户在启动您的应用时，有可用的开屏广告。

#### 处理请求的回调

您可以实现 Adx3AdLoadingDelegate 以用来监听开屏广告请求是否成功，方法如下：

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

```swift
func didFinishLoadingAD(withPlacementID placementID: String!) {
    print("----\(placementID!)----")
}
    
func didFailToLoadAD(withPlacementID placementID: String!, error: Error!) {
    print("----\(error.debugDescription)----")
}
```

{% endtab %}

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

```objectivec
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
    NSLog(@"----%@----", placementID);
}

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

{% endtab %}
{% endtabs %}

接下来，添加一个方法用来展示请求到的广告

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

```swift
func tryToPresentAd() {
    if Adx3FullScreenAd.sharedManager().fullScreenIsReady() {
        Adx3FullScreenAd.sharedManager().showScreenView(withContrller: self, delegate: self) { isSuccess in
                
        };
    }else {
        self.requestAppOpenAd()
    } 
}
```

{% endtab %}

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

```objectivec
- (void)tryToPresentAd {
    if ([[Adx3FullScreenAd sharedManager] fullScreenIsReady]) {
          UIViewController *rootController = self.window.rootViewController;
          [[Adx3FullScreenAd sharedManager] showScreenViewWithContrller:rootController delegate:self success:^(BOOL isSuccess) {
            
          ];
    }else {
          // If no ad is available, make a new request
          [self requestAppOpenAd];
    }
}
```

{% endtab %}
{% endtabs %}

该方法会检查广告是否存在，如果存在则会在您的根视图上进行展示。如果没有可用的广告，会重新发起一次新的请求。您可以将此方法添加到您想添加的任何位置。

#### 处理展示的回调

当应用展示开屏广告时，您可以借助 Adx3FullScreenDeleagte 处理某些展示事件，可选。示例如下：

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

```swift
func fullScreenDidStartPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
}
    
func fullScreenDidEndPlayingVideo(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
}
    
func fullScreenDidFailToPlayVideo(forPlacementID placementID: String!, error: Error!, extra: [AnyHashable : Any]!) {
        
}
    
func fullScreenDidClose(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
}
    
func fullScreenDidClick(forPlacementID placementID: String!, extra: [AnyHashable : Any]!) {
        
}
```

{% endtab %}

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

```objectivec
-(void)fullScreenDidStartPlayingVideoForPlacementID:(NSString*)placementID extra:(NSDictionary*)extra {

}

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

}

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

}

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

}

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

}
```

{% 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/kai-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.
