---
metadata:
  - name: generator
    content: Diplodoc Platform v5.57.3
alternate:
  - https://ads.yandex.com/helpcenter/en/support/migration/admob-ya-ads-ios.md
  - https://ads.yandex.com/helpcenter/ru/support/migration/admob-ya-ads-ios.md
  - https://ads.yandex.com/helpcenter/zh/support/migration/admob-ya-ads-ios.md
  - href: ru/support/migration/admob-ya-ads-ios.md
    type: text/markdown
    title: Markdown version
  - href: ../llms.txt
    type: text/markdown
    title: llms.txt
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/ru/llms.txt

# Миграция с Google AdMob на Медиацию Яндекса на iOS

Чтобы заменить рекламу Google AdMob на Медиацию Яндекса на iOS, внесите в свой код следующие изменения.


## Подключение SDK {#sdk}

Откройте Podfile вашего проекта и добавьте строку в цель вашего приложения:

{% list tabs %}

- Google AdMob

  ```bash
  pod 'Google-Mobile-Ads-SDK'
  ```

- Yandex Ads

  ```bash
  pod 'YandexMobileAds'
  ```

{% endlist %}

Обновите свой `Info.plist`:

{% list tabs %}

- Google AdMob

  ```xml
  <key>GADApplicationIdentifier</key>
  <string>ca-app-pub-3940256099942544~1458002511</string>
  <key>SKAdNetworkItems</key>
    <array>
      <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>cstr6suwn9.skadnetwork</string>
      </dict>
  .....
  ```

- Yandex Ads

  ```xml
  <key>SKAdNetworkItems</key>
  <array>
      <dict>
          <key>SKAdNetworkIdentifier</key>
          <string>zq492l623r.skadnetwork</string>
      </dict>
  </array>
  ```

{% endlist %}

Перед загрузкой рекламы инициализируйте библиотеку:

{% list tabs %}

- Google AdMob

  ```java
  @UIApplicationMain
  class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

  GADMobileAds.sharedInstance().start(completionHandler: nil)
      return true
    }
  }
  ```

- Yandex Ads

  ```java
  // Не требуется
  ```

{% endlist %}

## Форматы объявлений {#format}

### Interstitial {#interstitial}

#### Загрузка объявления {#loading-interstitial-ads}

{% list tabs %}

- Google AdMob

  ```java
  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
                        }
      )
    }
  }
  ```

- Yandex Ads

  ```java
  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)
  }
  }
  ```

{% endlist %}

#### Установка коллбеков рекламы {#setting-callbacks-interstitial}

{% list tabs %}

- Google AdMob

  ```java
  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.")
    }
  ```

- Yandex Ads

  ```java
  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")
      }
  }
  ```

{% endlist %}

#### Показать объявление {#show-interstitial-ads}

{% list tabs %}

- Google AdMob

  ```java
  @IBAction func doSomething(_ sender: Any) {
    if interstitial != nil {
      interstitial.present(fromRootViewController: self)
    } else {
      print("Ad wasn't ready")
    }
  }
  ```

- Yandex Ads

  ```java
  @IBAction func doSomething(_ sender: Any) {
  if interstitialAd?.loaded ?? false {
          interstitialAd?.present(from: self)
      } else {
          print("Ad wasn't ready")
      }
  }
  ```

{% endlist %}

### Rewarded {#rewarded}

#### Загрузка объявления {#loading-rewarded-ad}

{% list tabs %}

- Google AdMob

  ```java
  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.")
      }
      )
    }
  }
  ```

- Yandex Ads

  ```java
  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)
      }
  }
  ```

{% endlist %}

#### Установка коллбеков рекламы {#setting-callbacks-rewarded-ad}

{% list tabs %}

- Google AdMob

  ```java
  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.")
    }
  ```

- Yandex Ads

  ```java
  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")
      }
  }
  ```

{% endlist %}

#### Показать объявление {#show-rewarded-ads}

{% list tabs %}

- Google AdMob

  ```java
  @IBAction func doSomething(_ sender: Any) {
    if interstitial != nil {
      interstitial.present(fromRootViewController: self)
    } else {
      print("Ad wasn't ready")
    }
  }
  ```

- Yandex Ads

  ```java
  @IBAction func doSomething(_ sender: Any) {
  if rewardedAd?.loaded ?? false {
          rewardedAd?.present(from: self)
      } else {
          print("Ad wasn't ready")
      }
  }
  ```

{% endlist %}

### Banner {#banner}

#### Конфигурация {#configuration}

{% list tabs %}

- Google AdMob

  ```java
  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
    }
  }
  ```

- Yandex Ads

  ```java
  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)
      }
  }
  ```

{% endlist %}

#### Отображение объявления {#displaying-ads}

{% list tabs %}

- Google AdMob

  ```java
  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)
        ])
  ```

- Yandex Ads

  ```java
  view.addSubview(bannerView)
  bannerView.displayAtBottom(in: view)
  // also possible to use regular autolayout
  ```

{% endlist %}

#### Установка коллбеков рекламы {#setting-callbacks-banner}

{% list tabs %}

- Google AdMob

  ```java
  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")
  }
  ```

- Yandex Ads

  ```java
  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")
      }

  }
  ```

{% endlist %}

#### Загрузка объявления {#loading-banner}

{% list tabs %}

- Google AdMob

  ```java
  bannerView.load(GADRequest())
  ```

- Yandex Ads

  ```java
  bannerView.loadAd(with: YMAAdRequest())
  ```
{% endlist %}

<!-- source: ru/support/_includes/support.md -->
[Обратиться в службу поддержки](https://ads.yandex.com/helpcenter/ru/support/contact.md){.button}


<!-- endsource: ru/support/_includes/support.md -->
