> 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-6.md).

# 리워드비디오광고

<figure><img src="/files/QujWk8s8GvOUKBaqfYTZ" alt="" width="214"><figcaption></figcaption></figure>

## 인스턴스 생성

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

```swift
import APSSPSDK

var rewardVideoAd: APSSPRewardVideoAd!

rewardVideoAd = APSSPRewardVideoAd(
    appKey: "YOUR_APP_KEY",
    placementId: "YOUR_PLACEMENT_ID",
    rootViewController: self
)
rewardVideoAd.delegate = self
```

{% endtab %}

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

```objc
@import APSSPSDK;

APSSPRewardVideoAd *rewardVideoAd = [[APSSPRewardVideoAd alloc] initWithAppKey:@"YOUR_APP_KEY"
                                                                    placementId:@"YOUR_PLACEMENT_ID"
                                                             rootViewController:self];
rewardVideoAd.delegate = self;
```

{% endtab %}
{% endtabs %}

## 유저 식별값 설정

유저 식별값은 리워드 비디오 시청 완료 시 완료 유저를 식별하기 위해 사용됩니다. **광고 load 전에 설정해야 합니다.**

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

```swift
APSSPAds.setUSerID(usn: "TEST_USN")
```

{% endtab %}

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

```objc
[APSSPAds setUSerIDWithUsn:@"TEST_USN"];
```

{% endtab %}
{% endtabs %}

## 리워드 비디오 광고 요청

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

```swift
rewardVideoAd.load()
```

{% endtab %}

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

```objc
[rewardVideoAd load];
```

{% endtab %}
{% endtabs %}

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

## 리워드 비디오 광고 노출

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

```swift
rewardVideoAd.present(from: self)
```

{% endtab %}

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

```objc
[rewardVideoAd presentFrom:self];
```

{% endtab %}
{% endtabs %}

## 리워드 비디오 광고 중단

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

```swift
rewardVideoAd.stopAd()
```

{% endtab %}

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

```objc
[rewardVideoAd stopAd];
```

{% endtab %}
{% endtabs %}

## 이벤트 리스너

| 이벤트 리스너                           | 설명               |
| --------------------------------- | ---------------- |
| `apsspRewardVideoAdLoadSuccess`   | 리워드 비디오 광고 로딩 성공 |
| `apsspRewardVideoAdLoadFail`      | 리워드 비디오 광고 로딩 실패 |
| `apsspRewardVideoAdShowSuccess`   | 리워드 비디오 광고 노출 성공 |
| `apsspRewardVideoAdShowFail`      | 리워드 비디오 광고 노출 실패 |
| `apsspRewardVideoAdClicked`       | 리워드 비디오 광고 클릭    |
| `apsspRewardVideoAdClosed`        | 리워드 비디오 광고 닫기    |
| `apsspRewardVideoAdPlayCompleted` | 리워드 비디오 광고 재생 완료 |

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

```swift
extension ViewController: APSSPRewardVideoAdDelegate {

    func apsspRewardVideoAdLoadSuccess(rewardVideoAd: APSSPRewardVideoAd) {
        rewardVideoAd.present(from: self)
    }

    func apsspRewardVideoAdLoadFail(rewardVideoAd: APSSPRewardVideoAd, error: APSSPNetworkError) {
    }

    func apsspRewardVideoAdShowSuccess(rewardVideoAd: APSSPRewardVideoAd) {
    }

    func apsspRewardVideoAdShowFail(rewardVideoAd: APSSPRewardVideoAd, error: APSSPNetworkError) {
    }

    func apsspRewardVideoAdClicked(rewardVideoAd: APSSPRewardVideoAd) {
    }

    func apsspRewardVideoAdClosed(rewardVideoAd: APSSPRewardVideoAd) {
    }

    func apsspRewardVideoAdPlayCompleted(rewardVideoAd: APSSPRewardVideoAd, adNetworkNo: Int, completed: Bool) {
        // adNetworkNo: 미디에이션 업체 번호
        // completed: 시청 정상 완료 여부
    }
}
```

{% endtab %}

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

```objc
- (void)apsspRewardVideoAdLoadSuccessWithRewardVideoAd:(APSSPRewardVideoAd *)rewardVideoAd {
    [rewardVideoAd presentFrom:self];
}

- (void)apsspRewardVideoAdLoadFailWithRewardVideoAd:(APSSPRewardVideoAd *)rewardVideoAd error:(enum APSSPNetworkError)error {
}

- (void)apsspRewardVideoAdShowSuccessWithRewardVideoAd:(APSSPRewardVideoAd *)rewardVideoAd {
}

- (void)apsspRewardVideoAdShowFailWithRewardVideoAd:(APSSPRewardVideoAd *)rewardVideoAd error:(enum APSSPNetworkError)error {
}

- (void)apsspRewardVideoAdClickedWithRewardVideoAd:(APSSPRewardVideoAd *)rewardVideoAd {
}

- (void)apsspRewardVideoAdClosedWithRewardVideoAd:(APSSPRewardVideoAd *)rewardVideoAd {
}

- (void)apsspRewardVideoAdPlayCompletedWithRewardVideoAd:(APSSPRewardVideoAd *)rewardVideoAd adNetworkNo:(NSInteger)adNetworkNo completed:(BOOL)completed {
}
```

{% endtab %}
{% endtabs %}

## CS 페이지 호출

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

```swift
APSSPAds.presentCSViewController(self, userID: "usn")
```

{% endtab %}

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

```objc
[APSSPAds presentCSViewController:self userID:@"usn"];
```

{% endtab %}
{% endtabs %}
