> For the complete documentation index, see [llms.txt](https://ios-docs.adster.tech/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ios-docs.adster.tech/ad-types/native-reward-ad.md).

# Native Reward Ad

To receive Native Ads, conform to the `MediationAdDelegate` protocol. Once the ad is loaded, you can populate your custom native ad view with the ad's data.

**Implementation:**

```swift
extension NativeRewardAdManager: MediationAdDelegate {
    func onNativeRewardAdLoaded(nativeRewardAd: AdsFramework.MediationNativeRewardAd) {
        nativeRewardAd.eventDelegate = self

        guard let nibObjects = Bundle.main.loadNibNamed("NativeRewardView", owner: nil, options: nil),
              let adView = nibObjects.first as? MediationNativeRewardAdView else {
            printLog("Could not load nib file for adView")
            return
        }

        (adView.headlineView as? UILabel)?.text = nativeRewardAd.headline
        (adView.bodyView as? UILabel)?.text = nativeRewardAd.body
        (adView.ctaView as? UIButton)?.setTitle(nativeRewardAd.callToAction, for: .normal)
        (adView.ctaView as? UIButton)?.isUserInteractionEnabled = false

        if let mediaView = nativeRewardAd.mediaView {
            addMediaViewToParentView(childView: mediaView, parentView: adView.mediaView)
        }

        adView.setNativeRewardAd(nativeRewardAd: nativeRewardAd)
        viewBanner.addSubview(adView)
    }

    func onAdFailedToLoad(error: AdError) {
        print("Native Reward Ad request failed with reason \(error.description)")
    }
}
```

**Reward Metadata:**

Native Reward Ads expose reward metadata through `nativeRewardAd.reward`

Example:

```swift
if let reward = nativeRewardAd.reward {
    let couponCode = reward.coupon?.code
    let redemptionUrl = reward.coupon?.redemptionUrl
    let expiresAt = reward.coupon?.expiresAt
    let brandName = reward.brand?.displayName
    let brandLogo = reward.brand?.logoUrl
    let description = reward.description
    let terms = reward.tnc
    let instructions = reward.redemptionInstructions

    print("Coupon code: \(couponCode ?? "")")
}
```

**Tracking Events:**

To track impression and click events for Native Reward Ads, conform to `MediationNativeRewardAdEventDelegate`:

```swift
extension NativeRewardAdManager: MediationNativeRewardAdEventDelegate {
    func recordNativeRewardClick() {
        print("Native reward ad clicked")
    }

    func recordNativeRewardImpression() {
        print("Native reward ad impression recorded")
    }
}
```

**Manual Click and Impression Tracking:**

If you are not using `MediationNativeRewardAdView`, or if you set custom click/impression handling, call these methods manually:

```swift
nativeRewardAd.recordNativeRewardImpression()
nativeRewardAd.recordNativeRewardClick()
```

**Cleanup:**

Destroy the ad when it is no longer needed:

```swift
nativeRewardAd.destroy()
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://ios-docs.adster.tech/ad-types/native-reward-ad.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
