Enabling interstitial ads

Warning.

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

An interstitial ad is a configurable ad that covers the entire screen and responds to clicks.

To enable advertising:

  1. Add the import:

    import YandexMobileAds
  2. Create @property where the link to the banner ad will be stored:

    var interstitialAd: YMAInterstitialAd!
  3. Perform initialization and pre-loading of the ad. This must be performed after displaying the app interface.

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

    interstitialAd = YMAInterstitialAd(adUnitID: “<AdUnitID>”)
    interstitialAd.delegate = self
    interstitialAd.load()

    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 YMAInterstitialAdDelegate protocol. The ad must be pre-loaded in the same orientation as it will be shown (otherwise, the ad won't be shown because the banner size doesn't match the screen size).

  4. Start displaying ads by using this method:

    func interstitialAdDidLoad(_ interstitialAd: YMAInterstitialAd) {
        interstitialAd.present(from: self)
    }
  5. 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 interstitialAdDidFail(toLoad interstitialAd: YMAInterstitialAd, error: Error)
func interstitialAdDidFail(toPresent interstitialAd: YMAInterstitialAd, error: Error)

For error descriptions, see YMAAdErrorCode.

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