Enabling rewarded ads

Warning.

This is an archived version of the documentation. Actual documentation for all platforms can be found here.

A rewarded ad is a configurable full-screen ad. The user gets a reward for viewing the ad.

To enable advertising:

  1. Add the import:

    import YandexMobileAds
  2. Create @property for storing the link to the ad:

    var rewardedAd: YMARewardedAd!
  3. Initialize the ad:
    rewardedAd = YMARewardedAd(adUnitID: “<AdUnitID>”)
    rewardedAd.delegate = self

    AdUnitId is a unique identifier in R-M-XXXXXX-Y format, which is assigned in the Partner Interface.

    In addition, self must conform to the YMARewardedAdDelegate protocol.

  4. Load an ad.
    rewardedAd.load()

    Optionally, you can use the YMAAdRequest class to transmit the data for targeting. For an example of using the class, see Interstitial ads.

    The ad must be pre-loaded in the same orientation as it will be shown (otherwise, the ad will not be shown because the banner size won't match the screen size).
  5. Start displaying ads by using this method:

    func rewardedAdDidLoad(_ rewardedAd: YMARewardedAd) {
        rewardedAd.present(from: self)
    }
  6. If you are using the “client-side reward” mechanism, implement the - rewardedAd:didReward: delegate method. It is called when the impression is registered and the user can be rewarded for viewing the ad. Use this chance to give the reward to the app user.

  7. You can optionally enable logging by using the +enableLogging method. If an impression wasn't registered, a message appears in the console.

    To find out why ads aren't working correctly, use the methods

    func rewardedAdDidFail(toLoad rewardedAd: YMARewardedAd, error: Error)
    func rewardedAdDidFail(toPresent rewardedAd: YMARewardedAd, error: Error)

    For error descriptions, see YMAAdErrorCode.

To see how the ad will be displayed in the app, use a demo AdUnitId:
  • demo-rewarded-yandex