> For the complete documentation index, see [llms.txt](https://adpopcornssp.gitbook.io/ssp-sdk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://adpopcornssp.gitbook.io/ssp-sdk/sdk/ios/ios-3.1.0+/undefined-1.md).

# 배너광고

<div><figure><img src="/files/Mf5pALMa42pPJ6gzraRz" alt=""><figcaption><p>320x50</p></figcaption></figure> <figure><img src="/files/6mJhasJbCGG5vPZ2HQg8" alt=""><figcaption><p>320x100</p></figcaption></figure> <figure><img src="/files/4IHqbqdOK4voxBNELZqD" alt=""><figcaption><p>300x250</p></figcaption></figure></div>

## 배너 뷰 인스턴스 생성

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

```swift
import APSSPSDK

var bannerView: APSSPBannerView!

bannerView = APSSPBannerView(
    appKey: "YOUR_APP_KEY",
    placementId: "YOUR_PLACEMENT_ID",
    bannerSize: .banner320x50
)
bannerView.delegate = self
bannerView.rootViewController = self
view.addSubview(bannerView)
```

{% endtab %}

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

```objc
@import APSSPSDK;

APSSPBannerView *bannerView = [[APSSPBannerView alloc] initWithAppKey:@"YOUR_APP_KEY"
                                                          placementId:@"YOUR_PLACEMENT_ID"
                                                           bannerSize:APSSPBannerSizeBanner320x50];
bannerView.delegate = self;
bannerView.rootViewController = self;
[self.view addSubview:bannerView];
```

{% endtab %}
{% endtabs %}

## 배너 광고 Placement ID 설정

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

```swift
bannerView.placementId = "배너광고_PLACEMENT_ID"
```

{% endtab %}

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

```objc
bannerView.placementId = @"배너광고_PLACEMENT_ID";
```

{% endtab %}
{% endtabs %}

## 배너 광고 요청 사이즈 설정

배너 사이즈는 4가지 옵션을 지원합니다.

<table><thead><tr><th width="198.19281005859375">Swift</th><th width="339.3125">Objective-C</th><th>크기</th></tr></thead><tbody><tr><td><code>.banner320x50</code></td><td><code>APSSPBannerSizeBanner320x50</code></td><td>320 × 50</td></tr><tr><td><code>.banner320x100</code></td><td><code>APSSPBannerSizeBanner320x100</code></td><td>320 × 100</td></tr><tr><td><code>.banner300x250</code></td><td><code>APSSPBannerSizeBanner300x250</code></td><td>300 × 250</td></tr><tr><td><code>.bannerAdaptiveSize</code></td><td><code>APSSPBannerSizeBannerAdaptiveSize</code></td><td>NAM 전용</td></tr></tbody></table>

{% hint style="warning" %}
`.bannerAdaptiveSize`의 경우 네이버 애드 매니저 이미지형 배너 전용 사이즈입니다. \
해당 사이즈를 사용하고자 하는 경우에는 사업팀(<monetize@adpopcorn.com>)에 문의해 주시기 바랍니다.
{% endhint %}

## 배너 광고 요청 갱신주기 설정

배너 광고에 대한 갱신주기를 설정합니다. 설정가능 범위는 30\~120초 사이이며 -1로 설정 시 자동으로 갱신되지 않습니다.

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

```swift
bannerView.adRefreshTime = 50        // 60 (Default)
```

{% endtab %}

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

```objc
bannerView.adRefreshTime = 50;        // 60 (Default)
```

{% endtab %}
{% endtabs %}

## 배너 광고 애니메이션

배너 광고는 총 6가지의 애니메이션을 추가할 수 있습니다.

<table><thead><tr><th width="180.8316650390625">Swift</th><th>Objective-C</th><th>설명</th></tr></thead><tbody><tr><td><code>.none</code></td><td><code>AnimationTypeNone</code></td><td>애니메이션 없음</td></tr><tr><td><code>.fadeIn</code></td><td><code>AnimationTypeFadeIn</code></td><td>페이드 인</td></tr><tr><td><code>.flipFromLeft</code></td><td><code>AnimationTypeFlipFromLeft</code></td><td>왼쪽으로 플립</td></tr><tr><td><code>.flipFromRight</code></td><td><code>AnimationTypeFlipFromRight</code></td><td>오른쪽으로 플립</td></tr><tr><td><code>.curlUp</code></td><td><code>AnimationTypeCurlUp</code></td><td>위쪽으로 회전</td></tr><tr><td><code>.curlDown</code></td><td><code>AnimationTypeCurlDown</code></td><td>아래쪽으로 회전</td></tr></tbody></table>

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

```swift
bannerView.animationType = .flipFromLeft        // .none (Default)
```

{% endtab %}

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

```objc
bannerView.animationType = AnimationTypeFlipFromLeft;        // .AnimationTypeNone (Default)
```

{% endtab %}
{% endtabs %}

## 배너 배경색 채우기

배너 광고가 나오는 뷰의 빈 공간에 배경색을 채울 수 있습니다.

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

```swift
bannerView.setAutoBgColor(false)        // true (Default)
```

{% endtab %}

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

```objc
[bannerView setAutoBgColor:NO];        // NO (Default)
```

{% endtab %}
{% endtabs %}

## 배너 뷰 광고 요청

배너 광고 노출을 원하는 시점에 `loadAd()` API를 호출하여 서버에 광고를 요청합니다.

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

```swift
bannerView.loadAd()
```

{% endtab %}

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

```objc
[bannerView loadAd];
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
loadAd 호출에 대한 결과로 광고 수신에 실패한 경우에는 loadAd 재호출을 하시면 안됩니다. \
**과도한 광고 요청 API 호출은 block 사유**가 됩니다.
{% endhint %}

## 배너 뷰 광고 중단

배너 광고 노출을 더 이상 하고 싶지 않은 시점에 호출합니다.

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

```swift
bannerView.stopAd()
```

{% endtab %}

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

```objc
[bannerView stopAd];
```

{% endtab %}
{% endtabs %}

## 이벤트 리스너

배너 광고를 불러올 때 발생하는 이벤트에 대한 리스너를 설정합니다.

| 이벤트 리스너                      | 설명          |
| ---------------------------- | ----------- |
| `apsspBannerViewLoadSuccess` | 배너 광고 로딩 성공 |
| `apsspBannerViewLoadFail`    | 배너 광고 로딩 실패 |
| `apsspBannerViewClicked`     | 배너 클릭 시     |
| `apsspBannerViewImpression`  | 배너 노출 시     |

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

```swift
extension ViewController: APSSPBannerViewDelegate {

    func apsspBannerViewLoadSuccess(bannerView: APSSPBannerView) {
    }

    func apsspBannerViewLoadFail(bannerView: APSSPBannerView, error: APSSPNetworkError) {
    }

    func apsspBannerViewClicked(bannerView: APSSPBannerView) {
    }

    func apsspBannerViewImpression(bannerView: APSSPBannerView) {
    }
}
```

{% endtab %}

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

```objc
- (void)apsspBannerViewLoadSuccessWithBannerView:(APSSPBannerView *)bannerView {
}

- (void)apsspBannerViewLoadFailWithBannerView:(APSSPBannerView *)bannerView error:(enum APSSPNetworkError)error {
}

- (void)apsspBannerViewClickedWithBannerView:(APSSPBannerView *)bannerView {
}

- (void)apsspBannerViewImpressionWithBannerView:(APSSPBannerView *)bannerView {
}
```

{% endtab %}
{% endtabs %}
