Rewarded ads

Rewarded ads are a popular fullscreen ad format where users receive incentives for viewing ads.

Ad impressions are opt-in: for example, users can initiate them to get game bonuses or extra lives.

Strong user motivation makes this ad format the most popular and profitable adoption in free apps.

Appearance

This guide will show how to integrate rewarded ads into iOS apps. Besides code samples and instructions, it contains format-specific recommendations and links to additional resources.

Prerequisite

  1. Follow the SDK integration steps described under Quick start.
  2. First, you need to initialize the advertising SDK.
  3. Make sure you're using the latest version of the Yandex Mobile Ads SDK, and if you're using mediation, the latest version of the unified build.

Implementation

Key steps for integrating rewarded ads:

  • Create and configure a RewardedAdLoader.
  • Load the ad.
  • If needed, set a delegate for the ad object and implement the required RewardedAdDelegate methods.
  • Render the ad.
  • Reward the user for viewing the ad.

Features of rewarded ad integration

  1. All calls to Yandex Mobile Ads SDK methods must be made from the main thread.

  2. We strongly advise against attempting to load a new ad immediately after a loading error. With completion handlers, this corresponds to the .failure case. With Swift Concurrency, it's the catch block. If you need to retry loading ads from the error handler, limit the number of retries. This helps prevent endless failed ad requests during network issues.

  3. We recommend maintaining a strong reference to the ad and its loader throughout the lifespan of the screen where the ad interaction is taking place.

Loading ads

To load rewarded ads, create an instance of the RewardedAdLoader class.

To load an ad, use the loadAd(with:completion:) method with a completion handler or the Swift Concurrency-powered loadAd(with:) method.

You can expand ad request parameters through AdRequest, by passing user interests, contextual page data, location, or other additional info. Adding extra context to ad requests can greatly improve ad relevance. To learn more, see Ad targeting.

The following example shows how to load a rewarded ad from the View Controller.

final class RewardedViewController: UIViewController {
    private lazy var rewardedAdLoader = RewardedAdLoader()
    private var rewardedAd: RewardedAd?

    func loadAd() async {
        let request = AdRequest(adUnitID: "R-M-XXXXX-YY")
        do {
            let ad = try await rewardedAdLoader.loadAd(with: request)
            rewardedAd = ad
            ad.delegate = self
        } catch {
            // Load error
        }
    }
}
final class RewardedViewController: UIViewController {
    private lazy var rewardedAdLoader = RewardedAdLoader()
    private var rewardedAd: RewardedAd?

    func loadAd() {
        let request = AdRequest(adUnitID: "R-M-XXXXX-YY")
        rewardedAdLoader.loadAd(with: request) { [weak self] result in
            switch result {
            case .success(let ad):
                self?.rewardedAd = ad
                ad.delegate = self
            case .failure:
                // Load error
                break
            }
        }
    }
}

Displaying ads

Rewarded ads are an incentivized ad format that allows users to earn rewards by viewing ads. These rewards may include extra lives or the ability to advance to the next level in a game. The reward format is determined by the app itself.

Once the rewarded ad loads, save and display it.

final class RewardedViewController: UIViewController {
    private lazy var rewardedAdLoader = RewardedAdLoader()
    private var rewardedAd: RewardedAd?

    func showAd() {
        rewardedAd?.show(from: self)
    }
}

Reward issuance

Counted impressions trigger the rewardedAd(_ rewardedAd: RewardedAd, didReward reward: Reward) method of the RewardedAdDelegate delegate. Use this method to reward the app user.

final class RewardedViewController: UIViewController {
    private var rewardedAd: RewardedAd?
}

extension RewardedViewController: RewardedAdDelegate {
    func rewardedAd(_ rewardedAd: RewardedAd, didReward reward: Reward) {
        sendReward(reward)
    }
}

Testing rewarded ad integration

Using demo ad units for ad testing

Use test ads to check your ad integration and the app itself. To make sure that test ads are returned for each ad request, you can use a special demo ad placement ID.

Demo adUnitId: demo-rewarded-yandex.

Warning

Before publishing your app in the store, make sure to replace the demo placement ID with the real ID you obtained in the Yandex Advertising Network interface.

For the list of all available demo ad placement IDs, see Demo ad units for testing.

Testing ad integration

You can test your ad integration using the native Console tool.

To view detailed logs, call the YandexAds class's enableLogging method.

YandexAds.enableLogging()

To view SDK logs, go to the Console tool and set Subsystem = com.mobile.ads.ads.sdk. You can filter logs by category or error level.

If you're having problems integrating ads, you'll get a detailed report on the issues and recommendations for how to fix them.

Additional resources