> For the complete documentation index, see [llms.txt](https://aatkit.gitbook.io/ios-integration/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://aatkit.gitbook.io/ios-integration/formats/rewarded-video.md).

# Rewarded Video

In general, rewarded videos are similar to fullscreen ads in the aspect that it covers the whole screen of the device. What rewarded video ads add is the ability to reward the user when he watches the videos.

### Create Placement <a href="#create-placement" id="create-placement"></a>

To create an instance of [AATRewardedVideoPlacement](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatrewardedvideoplacement), use the following API:

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

```swift
var placement = AATSDK.createRewardedVideoPlacement(name: "<PLACEMENT_NAME>")
```

{% endtab %}

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

```objectivec
id<AATRewardedVideoPlacement> placement = [AATSDK createRewardedVideoPlacementWithName:@"<PLACEMENT_NAME>"];
```

{% endtab %}
{% endtabs %}

### Listen to Callbacks (Optional) <a href="#listen-to-callbacks-optional" id="listen-to-callbacks-optional"></a>

Through the use of [AATRewardedVideoPlacementDelegate](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatrewardedvideoplacementdelegate), you can listen to the different placement callbacks.

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

```swift
placement.delegate = self
```

{% endtab %}

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

```objectivec
placement.delegate = self;
```

{% endtab %}
{% endtabs %}

#### AATReward

When the user is rewarded while watching a rewarded video, the placement will notify you through its delegate method: `func aatUserEarnedIncentive(placement: AATPlacement, aatReward: AATReward)` passing itself and an [AATReward](https://docs.gravite.net/aatkit/ios/docs/documentation/aatkit/aatreward) instance.

### Request Ad

You can load ads for the rewarded video placement either automatically or manually.

#### Automatic Reload <a href="#automatic-reload" id="automatic-reload"></a>

To automatically load rewarded video Placement:

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

```swift
placement.startAutoReload()
```

{% endtab %}

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

```objectivec
[self.placement startAutoReload];
```

{% endtab %}
{% endtabs %}

This way the rewarded video placement will always try to have an ad ready. Please also remember to stop the auto-reload when it is no longer needed:

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

```
placement.stopAutoReload()
```

{% endtab %}

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

```objectivec
[self.placement stopAutoReload];
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
The rewarded video placement fires the `aatHaveAd(:)` delegate method only once per loaded ad. So, Before starting the auto-reload, you should check for ads from the previous load/auto-reload using the placement [has ad](#has-ad) API.
{% endhint %}

#### Manual Load <a href="#manual-load" id="manual-load"></a>

To manually load the rewarded video placement:

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

```swift
placement.reload()
```

{% endtab %}

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

```objectivec
[placement reload];
```

{% endtab %}
{% endtabs %}

### Display Ad <a href="#display-a-d" id="display-a-d"></a>

the AATKit can be told to display a rewarded video placement using the following method:

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

```swift
placement.show()
```

{% endtab %}

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

```objectivec
[placement show];
```

{% endtab %}
{% endtabs %}

The `show()` method will return a bool value indicating whether the rewarded video placement could be displayed or not. This means whether the rewarded video placement has a ready-rewarded video ad or not.

### Ad Info

After loading a rewarded video, you can access the loaded ad information by accessing the adInfo property of the rewarded video placement:

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

```swift
func aatHaveAd(placement: AATPlacement) {
    // The placement has loaded a new ad
    let adInfo = self.placement?.adInfo
}
```

{% endtab %}

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

```objectivec
- (void)aatHaveAdWithPlacement:(id<AATPlacement>)placement {
    // The placement has loaded a new ad
    AATAdInfo *adInfo = self.placement.adInfo;
}
```

{% endtab %}
{% endtabs %}

### Mute Ad

Some ad networks allow muting rewarded video ads. Use the following API to mute video ads:

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

```swift
AATSDK.setVideoAdsMuted(true)
```

{% endtab %}

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

```objectivec
[AATSDK setVideoAdsMuted:YES];
```

{% endtab %}
{% endtabs %}

{% hint style="info" %}
Currently only AdMob, DFP, AppLovin, Mintegral and GraviteRTB support this feature.
{% endhint %}

### Has Ad

The rewarded video placement provides an API to check if it has a loaded ad.

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

```swift
let hasAd = placement.hasAd()
```

{% endtab %}

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

```objectivec
BOOL hasAd = [self.placement hasAd];
```

{% endtab %}
{% endtabs %}

### Complete Code Example <a href="#complete-code-example" id="complete-code-example"></a>

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

```swift
class ViewController: UIViewController {
    // Create the placement
    var placement = AATSDK.createRewardedVideoPlacement(name: "<PLACEMENT_NAME>")
 
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        
        // [IMPORTANT] Notify AATKit about the currently active view controller.
        AATSDK.controllerViewDidAppear(controller: self)
        
        // Set placement delegate to listen to the callbacks.
        placement.delegate = self
        
        // Start autoreloading the placement.
        placement.startAutoReload()
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        // [IMPORTANT] Remove the currently active view controller.
        AATSDK.controllerViewWillDisappear()
        // [IMPORTANT] Stop placement autoreload.
        placement?.stopAutoReload()
    }
    
    @IBAction func watchVideo(_ sender: UIButton) {
        // An example for showing the rewarded video ad when the user clicks on "watch Video" button.
        if placement?.show() == false {
            // Show a message to the user telling: "Currently, no video available. Please try again later."
        }
    }
}

extension ViewController: AATRewardedVideoPlacementDelegate {
    func aatUserEarnedIncentive(placement: AATPlacement, aatReward: AATReward) {
        // The user has earned an incentive for this placement.
    }
    
    func aatHaveAd(placement: AATPlacement) {
        // The placement has loaded a new ad.
    }

    func aatNoAd(placement: AATPlacement) {
        // The placement could not load a new ad.
    }
    
    func aatAdCurrentlyDisplayed(placement: AATPlacement) {
        // Ad has been displayed on the screen
    }

    func aatResumeAfterAd(placement: AATPlacement) {
        // Back to the app.
    }
}
```

{% endtab %}

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

```objectivec
@interface ViewController () <AATRewardedVideoPlacementDelegate>
@property id<AATRewardedVideoPlacement> placement;
@end

@implementation ViewController
- (void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    
    // [IMPORTANT] Notify AATKit about the currently active view controller.
    [AATSDK controllerViewDidAppearWithController:self];
    
    // Create the placement.
    self.placement = [AATSDK createRewardedVideoPlacementWithName:@"<PLACEMENT_NAME>"];
    
    // Set placement delegate to listen to the callbacks.
    self.placement.delegate = self;
    
    // Start autoreloading the placement.
    [self.placement startAutoReload];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // [IMPORTANT] Remove the currently active view controller.
    [AATSDK controllerViewWillDisappear];
    // [IMPORTANT] Stop placement autoreload.
    [self.placement stopAutoReload];
}

- (IBAction)watchVideo:(UIButton *)sender {
    // An example for showing the rewarded video ad when the user clicks on "Watch Video" button.
    if (![placement show]) {
        // Show an alert box to the user telling: "Currently, no video available. Please try again later."
    }
}

#pragma mark - AATRewardedVideoPlacementDelegate
func aatUserEarnedIncentive(placement: AATPlacement, aatReward: AATReward) {
    // The user has earned an incentive for this placement.
}
    
- (void)aatHaveAdWithPlacement:(id<AATPlacement>)placement {
    // The placement has loaded a new ad.
}

- (void)aatNoAdWithPlacement:(id<AATPlacement>)placement {
    // The placement could not load a new ad.
}

- (void)aatAdCurrentlyDisplayedWithPlacement:(id<AATPlacement>)placement {
    // Ad has been displayed on the screen
}

- (void)aatResumeAfterAdWithPlacement:(id<AATPlacement>)placement {
    // Back to the app.
}
@end
```

{% endtab %}
{% endtabs %}
