Migrating from AdMob to Yandex mediation

Warning.

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

To replace AdMob ads with Yandex Ads mediation on iOS, make the following changes to your code.

Integrating the SDK

Open the Podfile of your project and add the line below to your app's target:

AdMob Yandex Ads
pod 'Google-Mobile-Ads-SDK'
Copied to clipboard
pod 'YandexMobileAds'
Copied to clipboard
AdMob Yandex Ads
pod 'Google-Mobile-Ads-SDK'
Copied to clipboard
pod 'YandexMobileAds'
Copied to clipboard

Update your Info.plist:

AdMob Yandex Ads
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<key>SKAdNetworkItems</key>
  <array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string>cstr6suwn9.skadnetwork</string>
    </dict>
.....
Copied to clipboard
<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>zq492l623r.skadnetwork</string>
    </dict>
</array>
Copied to clipboard
AdMob Yandex Ads
<key>GADApplicationIdentifier</key>
<string>ca-app-pub-3940256099942544~1458002511</string>
<key>SKAdNetworkItems</key>
  <array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string>cstr6suwn9.skadnetwork</string>
    </dict>
.....
Copied to clipboard
<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>zq492l623r.skadnetwork</string>
    </dict>
</array>
Copied to clipboard

Before loading ads, initialize the library:

AdMob Yandex Ads
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(_ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
   
GADMobileAds.sharedInstance().start(completionHandler: nil)
    return true
  }
}
Copied to clipboard
// Not required
Copied to clipboard
AdMob Yandex Ads
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

  func application(_ application: UIApplication,
      didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
   
GADMobileAds.sharedInstance().start(completionHandler: nil)
    return true
  }
}
Copied to clipboard
// Not required
Copied to clipboard

Ad formats

Interstitial

Loading ads
AdMob Yandex Ads
class ViewController: UIViewController {

  private var interstitial: GADInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    let request = GADRequest()
    GADInterstitialAd.load(withAdUnitID:"ca-app-pub-3940256099942544/4411468910",
                                request: request,
                      completionHandler: { [self] ad, error in
                        if let error = error {
                          print("Failed to load interstitial ad with error: \(error.localizedDescription)")
                          return
                        }
                        interstitial = ad
                      }
    )
  }
}
Copied to clipboard
class ViewController: UIViewController {
var interstitialAd: YMAInterstitialAd?

override func viewDidLoad() {
    super.viewDidLoad()
    interstitialAd = YMAInterstitialAd(adUnitID: "demo-interstitial-yandex")
    interstitialAd?.delegate = self;
    let request = YMAAdRequest()
     interstitialAd?.load(with: request)
}
}
Copied to clipboard
AdMob Yandex Ads
class ViewController: UIViewController {

  private var interstitial: GADInterstitialAd?

  override func viewDidLoad() {
    super.viewDidLoad()
    let request = GADRequest()
    GADInterstitialAd.load(withAdUnitID:"ca-app-pub-3940256099942544/4411468910",
                                request: request,
                      completionHandler: { [self] ad, error in
                        if let error = error {
                          print("Failed to load interstitial ad with error: \(error.localizedDescription)")
                          return
                        }
                        interstitial = ad
                      }
    )
  }
}
Copied to clipboard
class ViewController: UIViewController {
var interstitialAd: YMAInterstitialAd?

override func viewDidLoad() {
    super.viewDidLoad()
    interstitialAd = YMAInterstitialAd(adUnitID: "demo-interstitial-yandex")
    interstitialAd?.delegate = self;
    let request = YMAAdRequest()
     interstitialAd?.load(with: request)
}
}
Copied to clipboard
Setting ad callbacks
AdMob Yandex Ads
interstitial?.fullScreenContentDelegate = self
...

/// Tells the delegate that the ad failed to present full screen content.
  func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
    print("Ad did fail to present full screen content.")
  }

  /// Tells the delegate that the ad will present full screen content.
  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad will present full screen content.")
  }

  /// Tells the delegate that the ad dismissed full screen content.
  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad did dismiss full screen content.")
  }
Copied to clipboard
self.interstitialAd?.delegate = self;
...

extension ViewController: YMAInterstitialAdDelegate {
    func interstitialAdDidLoad(_ interstitialAd: YMAInterstitialAd) {
        print("Ad loaded")
    }

    func interstitialAdDidFail(toLoad interstitialAd: YMAInterstitialAd, error: Error) {
        print("Loading failed. Error: \(error)")
    }

func interstitialAd(_ interstitialAd: YMAInterstitialAd, didTrackImpressionWith impressionData: YMAImpressionData?) {
        print("Ad imprassion was tracked.")
    }

    func interstitialAdDidClick(_ interstitialAd: YMAInterstitialAd) {
        print("Ad clicked")
    }

func interstitialAdDidFail(toPresent interstitialAd: YMAInterstitialAd, error: Error) {
        print("Failed to present interstitial. Error: \(error)")
    }

    func interstitialAdWillAppear(_ interstitialAd: YMAInterstitialAd) {
        print("Interstitial ad will appear")
    }

    func interstitialAdDidDisappear(_ interstitialAd: YMAInterstitialAd) {
        print("Interstitial ad did disappear")
    }
}
Copied to clipboard
AdMob Yandex Ads
interstitial?.fullScreenContentDelegate = self
...

/// Tells the delegate that the ad failed to present full screen content.
  func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
    print("Ad did fail to present full screen content.")
  }

  /// Tells the delegate that the ad will present full screen content.
  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad will present full screen content.")
  }

  /// Tells the delegate that the ad dismissed full screen content.
  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad did dismiss full screen content.")
  }
Copied to clipboard
self.interstitialAd?.delegate = self;
...

extension ViewController: YMAInterstitialAdDelegate {
    func interstitialAdDidLoad(_ interstitialAd: YMAInterstitialAd) {
        print("Ad loaded")
    }

    func interstitialAdDidFail(toLoad interstitialAd: YMAInterstitialAd, error: Error) {
        print("Loading failed. Error: \(error)")
    }

func interstitialAd(_ interstitialAd: YMAInterstitialAd, didTrackImpressionWith impressionData: YMAImpressionData?) {
        print("Ad imprassion was tracked.")
    }

    func interstitialAdDidClick(_ interstitialAd: YMAInterstitialAd) {
        print("Ad clicked")
    }

func interstitialAdDidFail(toPresent interstitialAd: YMAInterstitialAd, error: Error) {
        print("Failed to present interstitial. Error: \(error)")
    }

    func interstitialAdWillAppear(_ interstitialAd: YMAInterstitialAd) {
        print("Interstitial ad will appear")
    }

    func interstitialAdDidDisappear(_ interstitialAd: YMAInterstitialAd) {
        print("Interstitial ad did disappear")
    }
}
Copied to clipboard
Show ads
AdMob Yandex Ads
@IBAction func doSomething(_ sender: Any) {
  if interstitial != nil {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}
Copied to clipboard
@IBAction func doSomething(_ sender: Any) {
if interstitialAd?.loaded ?? false {
        interstitialAd?.present(from: self)
    } else {
        print("Ad wasn't ready")
    }
}
Copied to clipboard
AdMob Yandex Ads
@IBAction func doSomething(_ sender: Any) {
  if interstitial != nil {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}
Copied to clipboard
@IBAction func doSomething(_ sender: Any) {
if interstitialAd?.loaded ?? false {
        interstitialAd?.present(from: self)
    } else {
        print("Ad wasn't ready")
    }
}
Copied to clipboard

Rewarded

Loading ads
AdMob Yandex Ads
class ViewController: UIViewController {

  private var rewardedAd: GADRewardedAd?

  func loadRewardedAd() {
    let request = GADRequest()
    GADRewardedAd.load(withAdUnitID:"ca-app-pub-3940256099942544/1712485313",
                       request: request,
                       completionHandler: { [self] ad, error in
      if let error = error {
        print("Failed to load rewarded ad with error: \(error.localizedDescription)")
        return
      }
      rewardedAd = ad
      print("Rewarded ad loaded.")
    }
    )
  }
}
Copied to clipboard
class ViewController: UIViewController {
    var rewardedAd: YMARewardedAd?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        rewardedAd = YMARewardedAd(adUnitID: "demo-rewarded-yandex")
        rewardedAd?.delegate = self
        let request = YMAAdRequest()
        rewardedAd?.load(with: request)
    }
}
Copied to clipboard
AdMob Yandex Ads
class ViewController: UIViewController {

  private var rewardedAd: GADRewardedAd?

  func loadRewardedAd() {
    let request = GADRequest()
    GADRewardedAd.load(withAdUnitID:"ca-app-pub-3940256099942544/1712485313",
                       request: request,
                       completionHandler: { [self] ad, error in
      if let error = error {
        print("Failed to load rewarded ad with error: \(error.localizedDescription)")
        return
      }
      rewardedAd = ad
      print("Rewarded ad loaded.")
    }
    )
  }
}
Copied to clipboard
class ViewController: UIViewController {
    var rewardedAd: YMARewardedAd?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        rewardedAd = YMARewardedAd(adUnitID: "demo-rewarded-yandex")
        rewardedAd?.delegate = self
        let request = YMAAdRequest()
        rewardedAd?.load(with: request)
    }
}
Copied to clipboard
Setting ad callbacks
AdMob Yandex Ads
rewardedAd?.fullScreenContentDelegate = self
...

/// Tells the delegate that the ad failed to present full screen content.
  func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
    print("Ad did fail to present full screen content.")
  }

  /// Tells the delegate that the ad will present full screen content.
  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad will present full screen content.")
  }

  /// Tells the delegate that the ad dismissed full screen content.
  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad did dismiss full screen content.")
  }
Copied to clipboard
rewardedAd?.delegate = self
...

extension ViewController: YMARewardedAdDelegate {
    func rewardedAdDidLoad(_ rewardedAd: YMARewardedAd) {
        print("Rewarded ad loaded")
    }
    
    func rewardedAdDidFail(toLoad rewardedAd: YMARewardedAd, error: Error) {
        print("Loading failed. Error: %@", error)
    }

    func rewardedAd(_ rewardedAd: YMARewardedAd, didReward reward: YMAReward) {
        print("The user earned the reward")
    }

    func rewardedAdDidFail(toPresent rewardedAd: YMARewardedAd, error: Error) {
        print("Failed to present rewarded ad. Error: %@", error)
    }

    func rewardedAdDidClick(_ rewardedAd: YMARewardedAd) {
        print("Ad clicked")
    }

    func rewardedAd(_ rewardedAd: YMARewardedAd, didTrackImpressionWith impressionData: YMAImpressionData?) {
        print("Ad imprassion was tracked.")
    }
    
    func rewardedAdWillAppear(_ rewardedAd: YMARewardedAd) {
        print("Rewarded ad will appear")
    }

    func rewardedAdDidDisappear(_ rewardedAd: YMARewardedAd) {
        print("Rewarded ad did disappear")
    }
}
Copied to clipboard
AdMob Yandex Ads
rewardedAd?.fullScreenContentDelegate = self
...

/// Tells the delegate that the ad failed to present full screen content.
  func ad(_ ad: GADFullScreenPresentingAd, didFailToPresentFullScreenContentWithError error: Error) {
    print("Ad did fail to present full screen content.")
  }

  /// Tells the delegate that the ad will present full screen content.
  func adWillPresentFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad will present full screen content.")
  }

  /// Tells the delegate that the ad dismissed full screen content.
  func adDidDismissFullScreenContent(_ ad: GADFullScreenPresentingAd) {
    print("Ad did dismiss full screen content.")
  }
Copied to clipboard
rewardedAd?.delegate = self
...

extension ViewController: YMARewardedAdDelegate {
    func rewardedAdDidLoad(_ rewardedAd: YMARewardedAd) {
        print("Rewarded ad loaded")
    }
    
    func rewardedAdDidFail(toLoad rewardedAd: YMARewardedAd, error: Error) {
        print("Loading failed. Error: %@", error)
    }

    func rewardedAd(_ rewardedAd: YMARewardedAd, didReward reward: YMAReward) {
        print("The user earned the reward")
    }

    func rewardedAdDidFail(toPresent rewardedAd: YMARewardedAd, error: Error) {
        print("Failed to present rewarded ad. Error: %@", error)
    }

    func rewardedAdDidClick(_ rewardedAd: YMARewardedAd) {
        print("Ad clicked")
    }

    func rewardedAd(_ rewardedAd: YMARewardedAd, didTrackImpressionWith impressionData: YMAImpressionData?) {
        print("Ad imprassion was tracked.")
    }
    
    func rewardedAdWillAppear(_ rewardedAd: YMARewardedAd) {
        print("Rewarded ad will appear")
    }

    func rewardedAdDidDisappear(_ rewardedAd: YMARewardedAd) {
        print("Rewarded ad did disappear")
    }
}
Copied to clipboard
Show ads
AdMob Yandex Ads
@IBAction func doSomething(_ sender: Any) {
  if interstitial != nil {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}
Copied to clipboard
@IBAction func doSomething(_ sender: Any) {
if rewardedAd?.loaded ?? false {
        rewardedAd?.present(from: self)
    } else {
        print("Ad wasn't ready")
    }
}
Copied to clipboard
AdMob Yandex Ads
@IBAction func doSomething(_ sender: Any) {
  if interstitial != nil {
    interstitial.present(fromRootViewController: self)
  } else {
    print("Ad wasn't ready")
  }
}
Copied to clipboard
@IBAction func doSomething(_ sender: Any) {
if rewardedAd?.loaded ?? false {
        rewardedAd?.present(from: self)
    } else {
        print("Ad wasn't ready")
    }
}
Copied to clipboard

Banner

Configuration
AdMob Yandex Ads
class ViewController: UIViewController {

  var bannerView: GADBannerView!

  override func viewDidLoad() {
    super.viewDidLoad()
    
    // In this case, we instantiate the banner with desired ad size.
    bannerView = GADBannerView(adSize: GADAdSizeBanner)
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
  bannerView.rootViewController = self
  }
}
Copied to clipboard
class ViewController: UIViewController {
var bannerView: YMAAdView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Replace demo demo-banner-yandex0 with actual Ad Unit ID
        let adSize = YMAAdSize.stickySize(withContainerWidth: view.frame.width)
        bannerView = YMAAdView(adUnitID: "demo-banner-yandex", adSize: adSize)
    }
}
Copied to clipboard
AdMob Yandex Ads
class ViewController: UIViewController {

  var bannerView: GADBannerView!

  override func viewDidLoad() {
    super.viewDidLoad()
    
    // In this case, we instantiate the banner with desired ad size.
    bannerView = GADBannerView(adSize: GADAdSizeBanner)
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
  bannerView.rootViewController = self
  }
}
Copied to clipboard
class ViewController: UIViewController {
var bannerView: YMAAdView!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Replace demo demo-banner-yandex0 with actual Ad Unit ID
        let adSize = YMAAdSize.stickySize(withContainerWidth: view.frame.width)
        bannerView = YMAAdView(adUnitID: "demo-banner-yandex", adSize: adSize)
    }
}
Copied to clipboard
Displaying ads
AdMob Yandex Ads
bannerView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(bannerView)
    view.addConstraints(
      [NSLayoutConstraint(item: bannerView,
                          attribute: .bottom,
                          relatedBy: .equal,
                          toItem: bottomLayoutGuide,
                          attribute: .top,
                          multiplier: 1,
                          constant: 0),
       NSLayoutConstraint(item: bannerView,
                          attribute: .centerX,
                          relatedBy: .equal,
                          toItem: view,
                          attribute: .centerX,
                          multiplier: 1,
                          constant: 0)
      ])
Copied to clipboard
view.addSubview(bannerView)
bannerView.displayAtBottom(in: view)
// also possible to use regular autolayout
Copied to clipboard
AdMob Yandex Ads
bannerView.translatesAutoresizingMaskIntoConstraints = false
    view.addSubview(bannerView)
    view.addConstraints(
      [NSLayoutConstraint(item: bannerView,
                          attribute: .bottom,
                          relatedBy: .equal,
                          toItem: bottomLayoutGuide,
                          attribute: .top,
                          multiplier: 1,
                          constant: 0),
       NSLayoutConstraint(item: bannerView,
                          attribute: .centerX,
                          relatedBy: .equal,
                          toItem: view,
                          attribute: .centerX,
                          multiplier: 1,
                          constant: 0)
      ])
Copied to clipboard
view.addSubview(bannerView)
bannerView.displayAtBottom(in: view)
// also possible to use regular autolayout
Copied to clipboard
Setting ad callbacks
AdMob Yandex Ads
bannerView.delegate = self
...

func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
  print("bannerViewDidReceiveAd")
}

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
  print("bannerView:didFailToReceiveAdWithError: \(error.localizedDescription)")
}

func bannerViewDidRecordImpression(_ bannerView: GADBannerView) {
  print("bannerViewDidRecordImpression")
}

func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {
  print("bannerViewWillPresentScreen")
}

func bannerViewWillDismissScreen(_ bannerView: GADBannerView) {
  print("bannerViewWillDIsmissScreen")
}

func bannerViewDidDismissScreen(_ bannerView: GADBannerView) {
  print("bannerViewDidDismissScreen")
}
Copied to clipboard
bannerView.delegate = self
...

extension BannerViewController: YMAAdViewDelegate {
    func adViewDidLoad(_ adView: YMAAdView) {
        print("Ad loaded")
    }
    
    func adViewDidFailLoading(_ adView: YMAAdView, error: Error) {
        print("Ad failed loading. Error: \(error)")
    }
    
    func adViewDidClick(_ adView: YMAAdView) {
        print("Ad clicked")
    }
    
    func adView(_ adView: YMAAdView, didTrackImpressionWith impressionData: YMAImpressionData?) {
        print("Ad imprassion was tracked")
    }
    
}
Copied to clipboard
AdMob Yandex Ads
bannerView.delegate = self
...

func bannerViewDidReceiveAd(_ bannerView: GADBannerView) {
  print("bannerViewDidReceiveAd")
}

func bannerView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: Error) {
  print("bannerView:didFailToReceiveAdWithError: \(error.localizedDescription)")
}

func bannerViewDidRecordImpression(_ bannerView: GADBannerView) {
  print("bannerViewDidRecordImpression")
}

func bannerViewWillPresentScreen(_ bannerView: GADBannerView) {
  print("bannerViewWillPresentScreen")
}

func bannerViewWillDismissScreen(_ bannerView: GADBannerView) {
  print("bannerViewWillDIsmissScreen")
}

func bannerViewDidDismissScreen(_ bannerView: GADBannerView) {
  print("bannerViewDidDismissScreen")
}
Copied to clipboard
bannerView.delegate = self
...

extension BannerViewController: YMAAdViewDelegate {
    func adViewDidLoad(_ adView: YMAAdView) {
        print("Ad loaded")
    }
    
    func adViewDidFailLoading(_ adView: YMAAdView, error: Error) {
        print("Ad failed loading. Error: \(error)")
    }
    
    func adViewDidClick(_ adView: YMAAdView) {
        print("Ad clicked")
    }
    
    func adView(_ adView: YMAAdView, didTrackImpressionWith impressionData: YMAImpressionData?) {
        print("Ad imprassion was tracked")
    }
    
}
Copied to clipboard
Loading ads
AdMob Yandex Ads
bannerView.load(GADRequest())
Copied to clipboard
bannerView.loadAd(with: YMAAdRequest())
Copied to clipboard
AdMob Yandex Ads
bannerView.load(GADRequest())
Copied to clipboard
bannerView.loadAd(with: YMAAdRequest())
Copied to clipboard