# Rewarded

## Integración

Los anuncios recompensados (rewarded), al igual que los intersticiales, únicamente se pueden integrar a través de código. A continuación se muestra un sencillo ejemplo para entender su funcionamiento:

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

```swift
import UIKit
import WortiseSDK

class ViewController: UIViewController {

    private var rewardedAd: WARewardedAd!

    override func viewDidLoad() {
        super.viewDidLoad()
        ...
        rewardedAd = WARewardedAd(adUnitId: "test-rewarded")
        rewardedAd.loadAd()
    }

    override func willMove(toParent controller: UIViewController?) {
        super.willMove(toParent: controller)
        ...
        rewardedAd.destroy()
    }

    func showRewarded() {
        if rewardedAd.isAvailable {
            rewardedAd.showAd(from: self)
        }
    }
}
```

{% endtab %}
{% endtabs %}

## **Configuración del delegado**

Como en el resto de formatos, se puede añadir un delegate para recibir los diferentes eventos\
que sucedan durante el ciclo de vida del anuncio recompensado. Para ello, es necesario implementar la interfaz `WARewardedDelegate` como se muestra en el siguiente ejemplo:

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

```swift
extension ViewController : WARewardedDelegate {

    func didClick(rewardedAd: WARewardedAd) {
        // Invocado cuando el anuncio ha sido clickeado
    }

    func didComplete(rewardedAd: WARewardedAd, reward: WAReward) {
        // Invocado cuando el anuncio ha sido completado
    }

    func didDismiss(rewardedAd: WARewardedAd) {
        // Invocado cuando el anuncio ha sido cerrado
    }
    
    func didFailToLoad(rewardedAd: WARewardedAd, error: WAAdError) {
        // Invocado cuando el anuncio no se ha podido cargar
        // (por error o falta de inventario)
    }

    func didFailToShow(rewardedAd: WARewardedAd, error: WAAdError) {
        // Invocado cuando el anuncio no se ha podido mostrar
    }

    func didImpress(rewardedAd: WARewardedAd) {
        // Invocado cuando el anuncio ha generado una impresión
    }

    func didLoad(rewardedAd: WARewardedAd) {
        // Invocado cuando el anuncio ha sido cargado
    }
    
    func didPayRevenue(rewardedAd: WARewardedAd, data: WARevenueData) {
        // Invocado cuando el anuncio ha generado un ingreso
    }
 
    func didShow(rewardedAd: WARewardedAd) {
        // Invocado cuando el anuncio ha sido mostrado
    }
}
```

Una vez implementada la interfaz, se asigna el delegate a la instancia del anuncio:

```swift
rewardedAd.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.wortise.com/ios-sdk/integracion-del-sdk/rewarded.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.
