---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/ios/release/6-0-0-migration.md
  - https://ads.yandex.com/helpcenter/ru/dev/ios/release/6-0-0-migration.md
  - https://ads.yandex.com/helpcenter/zh/dev/ios/release/6-0-0-migration.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ads.yandex.com/helpcenter/zh/llms.txt

# 版本 6 迁移指南

<a href="dev/platforms"> <!--ссылка, куда ведет кнопка. Если внутренняя ссылка, пишем без .md и .html -->
<span class="button">其他平台</span> <!--текст на кнопке-->
</a>



{% note warning %}

请确保将您使用的 [Yandex 聚合](https://ads.yandex.com/helpcenter/zh/dev/ios/list-network.md) 适配器和 [第三方聚合网络适配器](https://ads.yandex.com/helpcenter/zh/dev/ios/third-party-mediation.md) 更新到最新版本。旧版本可能会导致适配器集成错误，从而导致您的广告无法投放。

{% endnote %}

## Banners

将 `YMAAdSize` 类重命名为 `YMABannerAdSize`。删除了之前标记为 **已弃用** 的 `flexibleSizeWithCGSize:(CGSize)size` 和 `fixedSizeWithCGSize:(CGSize)size` 方法。

根据广告类型使用方法：

使用 `stickySizeWithContainerWidth:(CGFloat)width` 方法创建自适应粘性横幅。

> 这是一个自动更新的小广告，放置在应用屏幕的顶部或底部。
>
> 广告与主要应用内容不重叠，常用于游戏应用中。
>
> 粘性横幅的高度是自动确定的，可根据设备的屏幕尺寸调整，并且不占用超过屏幕高度的 15%。

{% note warning %}

版本 6.0.0 添加了对自适应粘性横幅的自动刷新支持。

如果您之前已为粘性横幅实施了自动刷新，请禁用它。

{% endnote %}

使用 `inlineSizeWithWidth:(CGFloat)width maxHeight:(CGFloat)height` 方法创建自适应内联横幅。

> 自适应内联横幅是一种灵活的横幅广告格式，通过优化每个设备上的广告尺寸，实现最大效率。
>
> 横幅的高度会自动调整，可能会达到设备屏幕的高度。
>
> 通常，这种格式在基于内容来源的应用或允许主要关注广告的上下文环境中使用。

为了向后兼容，我们添加了 `fixedSizeWithWidth:(CGFloat)width height:(CGFloat)height` 方法，以替代 `fixedSizeWithCGSize:(CGSize)size` 方法。但是，我们不建议使用它。请改用 `stickySizeWithContainerWidth:(CGFloat)width`。在 SDK 6.0.0 中，横幅的高度是自动计算的，并且在发送广告请求之前已知。您可以在屏幕布局中使用此高度。

#|
||
移除了已弃用的方法 `flexibleSizeWithCGSize:(CGSize)size`
| **SDK 5**
```swift
let adSize = YMAAdSize.flexibleSize(withCGSize: CGSize(width: screenWidth, height: bannerHeight))
```
**SDK 6**
```swift
let adSize = YMABannerAdSize.inlineSize(withWidth: screenWidth, maxHeight: bannerHeight)
```
||
||
移除了已弃用的方法 `fixedSizeWithCGSize:(CGSize)size`
| **SDK 5**
```swift
let adSize = YMAAdSize.fixedSize(with: CGSize(width: screenWidth, height: bannerHeight))
```
**SDK 6**

如果您需要在内容中嵌入横幅，请使用 `inlineSizeWithWidth:(CGFloat)width maxHeight:(CGFloat)height` 方法。
```swift
let adSize = YMABannerAdSize.inlineSize(withWidth: screenWidth, maxHeight: bannerHeight)
```

或者，如果您需要在应用屏幕的顶部或底部放置横幅，则可以使用 `stickySizeWithContainerWidth:(CGFloat)width` 方法。
```swift
let adSize = YMABannerAdSize.stickySize(withContainerWidth: screenWidth)
```
||
||
将 `YMAAdSize` 类重命名为 `YMABannerAdSize`
| **SDK 5**
```swift
let adSize = YMAAdSize.fixedSizeWithWidth(width: screenWidth, height: bannerHeight)
```
**SDK 6**
```swift
let adSize = YMABannerAdSize.stickySize(withContainerWidth: screenWidth)
```
||
||
将 `YMAAdSize` 类重命名为 `YMABannerAdSize`
| **SDK 5**
```swift
let adSize = YMAAdSize.fixedSizeWithWidth(width: screenWidth, height: bannerHeight)
```
**SDK 6**
```swift
let adSize = YMABannerAdSize.stickySize(withContainerWidth: screenWidth)
```
||
|#

## 激励广告

 我们改变了创建和加载广告的方法。我们现在提供 `YMARewardedAdLoader` 加载器对象，用于加载广告，以及通过加载器的委托方法检索的 `YMARewardedAd` 广告对象。加载和呈现广告的内部逻辑保持不变。要了解有关新 API 的更多信息，请参阅 [SDK 参考](https://doc-static.yandex.net/src/support/RSYA-RMP/mobile-ads/ru/jazzy/Classes/RewardedAd.html)。

**SDK 5**

```swift
final class RewardedAdViewController: UIViewController {
   private lazy var rewardedAd: YMARewardedAd = {
        let rewardedAd = YMARewardedAd(adUnitID: "R-M-XXXXX-YY")
        rewardedAd.delegate = self
        return rewardedAd
    }()

    func loadAd() {
      rewardedAd.load()
    }

    func showAd() {
      rewardedAd.present(from: self)
    }

}

```

**SDK 6**

```swift
final class RewardedAdViewController: UIViewController {
   private var rewardedAd: YMARewardedAd?
   private lazy var rewardedAdLoader: YMARewardedAdLoader = {
        let loader = YMARewardedAdLoader()
        loader.delegate = self
        return loader
    }()

    func loadAd() {
      let configuration = YMAAdRequestConfiguration(adUnitID: "R-M-XXXXX-YY")
      rewardedAdLoader.loadAd(with: configuration)
    }

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

}

extension RewardedAdViewController: YMARewardedAdLoaderDelegate {
   func rewardedAdLoader(_ adLoader: YMARewardedAdLoader, didLoad rewardedAd: YMARewardedAd) {
        self.rewardedAd = rewardedAd
    }
}

```

## 插屏广告

 我们改变了创建和加载插屏广告的方法。我们现在提供 `YMAInterstitialAdLoader` 加载器对象，用于加载广告，以及通过加载器的委托方法检索的 `YMAInterstitialAd` 广告对象。广告加载和呈现的内部逻辑保持不变。要了解有关新 API 的更多信息，请参阅 [SDK 参考](https://doc-static.yandex.net/src/support/RSYA-RMP/mobile-ads/ru/jazzy/Classes/InterstitialAd.html)。

**SDK 5**

```swift
final class InterstitialAdViewController: UIViewController {
   private lazy var interstitialAd: YMAInterstitialAd = {
        let interstitialAd = YMAInterstitialAd(adUnitID: "R-M-XXXXX-YY")
        interstitialAd.delegate = self
        return interstitialAd
    }()

    func loadAd() {
      interstitialAd.load()
    }

    func showAd() {
      interstitialAd.present(from: self)
    }

}
```

**SDK 6**

```swift
final class InterstitialAdViewController: UIViewController {
   private var interstitialAd: YMAInterstitialAd?
   private lazy var interstitialAdLoader: YMInterstitialAdLoader = {
        let loader = YMInterstitialAdLoader()
        loader.delegate = self
        return loader
    }()

    func loadAd() {
      let configuration = YMAAdRequestConfiguration(adUnitID: "R-M-XXXXX-YY")
      interstitialAdLoader.loadAd(with: configuration)
    }

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

}

extension InterstitialAdViewController: YMAInterstitialAdLoaderDelegate {
   func interstitialAdLoader(_ adLoader: YMAInterstitialAdLoader, didLoad interstitialAd: YMAInterstitialAd) {
        self.interstitialAd = interstitialAd
    }
}
```

您可以在此处查找完整的集成示例：

* <!-- source: zh/dev/_includes/github-pubdev-links.md -->
  [GitHub](https://github.com/yandexmobile/yandex-ads-sdk-ios/blob/master/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Interstitial/InterstitialAdViewController.swift) 链接。
  <!-- endsource: zh/dev/_includes/github-pubdev-links.md -->
* <!-- source: zh/dev/_includes/github-pubdev-links.md -->
  [GitHub](https://github.com/yandexmobile/yandex-ads-sdk-ios/blob/master/Examples/YandexMobileAdsExample/YandexMobileAdsExample/Yandex/Rewarded/RewardedAdViewController.swift) 链接。
  <!-- endsource: zh/dev/_includes/github-pubdev-links.md -->

## 开屏广告

添加了新的广告格式：开屏广告。如需了解更多信息，请参阅 [开屏广告](https://ads.yandex.com/helpcenter/zh/dev/ios/app-open-ad.md)。

## 最低 iOS 版本

Yandex Mobile Ads 6.0 需要 iOS 13 或更高版本。如果您运行的是较早的 iOS 版本，请升级到 iOS 13。

## Yandex 聚合

{% note warning %}

请确保将您使用的 [Yandex 聚合](https://ads.yandex.com/helpcenter/zh/dev/ios/list-network.md) 适配器和 [第三方聚合网络适配器](https://ads.yandex.com/helpcenter/zh/dev/ios/third-party-mediation.md) 更新到最新版本。旧版本可能会导致适配器集成错误，从而导致您的广告无法投放。

{% endnote %}

### 新适配器版本

**Yandex 聚合适配器的当前版本（截至 SDK 6.0.0 版本）：**

* Digital Turbine (ex. AdColony)：4.9.0.5。
* AppLovin：11.11.2.0。
* Chartboost：9.4.0.0。
* Google：10.9.0.0。
* InMobi：10.5.5.1。
* IronSource：7.4.0.0。
* Mintegral：7.4.0.2。
* VK Ads (ex. myTarget)：5.18.0.1。
* Start.io：4.10.0.0。
* Unity Ads：4.8.0.1。

**第三方广告聚合平台的适配器的当前版本（截至 SDK 6.0.0 版本）：**

* Google AdMob (ex. AdMob)：10.9.0。
* IronSource：7.4.0。

### 重命名 Google AdMob (ex. AdMob) 适配器

我们将 `AdMobYandexMobileAdsAdapters` 适配器重命名为 `GoogleYandexMobileAdsAdapters`。如果您使用标准化聚合构建，则无需执行任何操作。如果您手动添加适配器，则需要编辑项目的 Podfile。

#|
|| **SDK 5**
```bash
pod 'AdMobYandexMobileAdsAdapters'
```
| **SDK 6**
```bash
pod 'GoogleYandexMobileAdsAdapters'
```
||
|#

