# Rewarded Ads

## What are Rewarded Ads? <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

Rewarded Ad Units reward a user within the app in exchange for completing the ad. This opt-in ad unit provides a less disruptive user experience along with high engagement from users.

## How to Display Rewarded Ads <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

### Integrate & Initialize HyprMX <a href="#bannerads6.0.0-initializeinitializeabannerview" id="bannerads6.0.0-initializeinitializeabannerview"></a>

Before you start, make sure you have correctly integrated and initialized the HyprMX SDK. To integrate and initialize HyprMX, see our [Setup Guide](/sdk-integration-guides/ios.md).

### Loading Rewarded Ads <a href="#quickstart-loading_adsloadinganddisplayingadvertisements" id="quickstart-loading_adsloadinganddisplayingadvertisements"></a>

HyprMX utilizes placements to load and display an ad. Placements are used to represent a point in your application's workflow where you'd like to show an ad. To load an ad to a placement, follow the steps below.

{% hint style="info" %}
If you don't have your placement information, please reach out to your account manager to configure your rewarded placements. In return, they will provide the names of the new placements.
{% endhint %}

{% stepper %}
{% step %}
Use the `getPlacement` API to retrieve a placement from HyprMX.

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

```swift
let rewardedPlacement = HyprMX.getPlacement("REWARDED")
```

{% endtab %}

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

```objectivec
HyprMXPlacement *rewardedPlacement = [HyprMX getPlacement:@"REWARDED"];
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}
To check for availability, run the following.

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

```swift
if await rewardedPlacement.loadAd() {
    print("Ad Available")
}
```

{% endtab %}

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

```objectivec
[rewardedPlacement loadAdWithCompletion:^(BOOL success) {
    if (success) {
        NSLog(@"Ad Available")
    }
}];
```

{% endtab %}
{% endtabs %}
{% endstep %}

{% step %}
To receive notification that the loaded ad has expired, implement the placement's `HyprMXPlacementExpiredDelegate`&#x20;

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

```swift
/** Called when ad loaded is no longer available for this placement */
func adExpired(placement: HyprMXPlacement) {
}
```

{% endtab %}

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

```objectivec
/** Called when ad loaded is no longer available for this placement */
- (void)adExpiredForPlacement:(HyprMXPlacement *)placement {
}
```

{% endtab %}
{% endtabs %}

Set the delegate on the placement:

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

```javascript
placement.expiredDelegate = myPlacementExpiredDelegateInstance
```

{% endtab %}

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

```python
placement.expiredDelegate = myPlacementExpiredDelegateInstance;
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

{% hint style="info" %}
HyprMX holds a weak reference to the placement expired delegate, so you must be sure to retain the delegate.
{% endhint %}

### Displaying Rewarded Ads <a href="#quickstart-loading_adsloadinganddisplayingadvertisements" id="quickstart-loading_adsloadinganddisplayingadvertisements"></a>

{% stepper %}
{% step %}
Before calling `showAdFromViewController:` on a placement you should confirm the ad state is still valid by running the following

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

```swift
rewardedPlacement.isAdAvailable
```

{% endtab %}

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

```objectivec
[rewardedPlacement isAdAvailable]
```

{% endtab %}
{% endtabs %}

Once an ad network has an available video, you will be ready to show the video to your users.
{% endstep %}

{% step %}
You can supply your current UIViewController when calling `showAdFromViewController:delegate:` for HyprMX to present from, or pass nil and HyprMX will present from the keyWindow.

If your App supports multi-window, it is recommended to always provide a View Controller to present from.

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

```swift
if rewardedPlacement.isAdAvailable {
  rewardedPlacement.showAd(from: self, delegate: self)
}
```

{% endtab %}

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

```objectivec
if ([rewardedPlacement isAdAvailable]) {
  [rewardedPlacement showAdFromViewController:self delegate:self];
}
```

{% endtab %}
{% endtabs %}

`showAdFromViewController:delegate:` will begin the presentation of an ad.&#x20;
{% endstep %}

{% step %}
For the best user experience, implement a delegate.&#x20;

Before you display the ad, make sure to pause any game action, including audio, to ensure the best experience for your users. You can disable them when you get the `adWillStartForPlacement:/adWillStart(placement:)` callback and re-enable when you get  `adDidCloseForPlacement:/adDidClose(placement:)`.

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

```swift
/** Called immediately before attempting to present an ad. */
func adWillStart(placement: HyprMXPlacement) {
}

/** Called upon conclusion of any ad presentation attempt */
func adDidClose(placement: HyprMXPlacement, didFinishAd finished: Bool) {
}

/** Called when user has earned a reward. */
func adDidReward(placement: HyprMXPlacement, rewardName: String?, rewardValue: Int) {
}

/** Called when an error occurs during ad presentation. */
func adDisplayError(_ error: Error, placement: HyprMXPlacement) {
}

/** Called when an ad has become visible on screen */
func adImpression(placement: HyprMXPlacement) {
}
```

{% endtab %}

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

```objectivec
/** Called immediately before attempting to present an ad. */
- (void)adWillStartForPlacement:(HyprMXPlacement *)placement {
}

/** Called upon conclusion of any ad presentation attempt */
- (void)adDidCloseForPlacement:(HyprMXPlacement *)placement didFinishAd:(BOOL)finished {
}

/** Called when user has earned a reward. */
- (void)adDidRewardForPlacement:(HyprMXPlacement *)placement rewardName:(NSString *)rewardName rewardValue:(NSInteger)rewardValue {
}

/** Called when an error occurs during ad presentation. */
-(void)adDisplayError:(NSError *)error placement:(HyprMXPlacement *)placement {
}

/** Called when an ad has become visible on screen */
- (void)adImpression:(HyprMXPlacement *)placement {
}
```

{% endtab %}
{% endtabs %}
{% endstep %}
{% endstepper %}

If you'd like, we can send server-to-server calls when ads are completed. Contact your account manager at HyprMX for more details.


---

# 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://documentation.hyprmx.com/sdk-integration-guides/ios/ad-formats/rewarded-ads.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.
