---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ads.yandex.com/helpcenter/en/dev/react-native/react-native-migration-800.md
  - https://ads.yandex.com/helpcenter/ru/dev/react-native/react-native-migration-800.md
  - https://ads.yandex.com/helpcenter/zh/dev/react-native/react-native-migration-800.md
  - href: zh/dev/react-native/react-native-migration-800.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/zh/llms.txt

# 迁移至版本 8 的指南

插件版本 8.0.0 移除了与新原生 SDK 不兼容的部分回调和 API。 本指南列出了您需要的代码更改。


## 1. 已移除 `BannerView` 回调

以下 `BannerView` 属性已被移除，不再受支持：

| 属性 | 平台 |
|------|----------|
| `onLeftApplication` | iOS、Android |
| `onWillPresentScreen` | iOS |
| `onDidDismissScreen` | iOS |
| `onReturnToApplication` | Android |
| `onAdClose` | iOS、Android |

**需要执行的操作**: 在所有使用 `BannerView` 的地方移除这些属性。

#### 之前

```tsx
<BannerView
  adRequest={{ adUnitId: 'R-M-XXXXX-YY' }}
  size={adSize}
  onAdLoaded={() => console.log('loaded')}
  onAdClicked={() => console.log('clicked')}
  onLeftApplication={() => console.log('left app')}
  onWillPresentScreen={() => console.log('will present')}
  onDidDismissScreen={() => console.log('did dismiss')}
  onReturnToApplication={() => console.log('returned')}
  onAdClose={() => console.log('closed')}
  onAdImpression={(e) => console.log('impression', e)}
  onAdFailedToLoad={(e) => console.log('failed', e)}
/>
```

#### 之后

```tsx
<BannerView
  adRequest={{ adUnitId: 'R-M-XXXXX-YY' }}
  size={adSize}
  onAdLoaded={() => console.log('loaded')}
  onAdClicked={() => console.log('clicked')}
  onAdImpression={(e) => console.log('impression', e)}
  onAdFailedToLoad={(e) => console.log('failed', e)}
/>
```

## 2. 将 `AdRequestConfiguration` 替换为 `AdRequest`

`AdRequestConfiguration` 已被移除。 将请求参数（包括 `adUnitId`）作为 `AdRequestParams` 直接传递到 `loadAd`。

**需要执行的操作：**

- 移除对 `AdRequestConfiguration` 的导入和构造。
- 将 `adUnitId` 和其他字段直接传递到 `loadAd`。

#### 之前

```tsx
import { InterstitialAdLoader, AdRequestConfiguration, Gender } from '@yandex-ads/react-native-yandex-ads';

const loader = await InterstitialAdLoader.create();
const config = new AdRequestConfiguration({
  adUnitId: 'R-M-XXXXX-YY',
  age: '25',
  gender: Gender.Male,
});
const ad = await loader.loadAd(config);
```

#### 之后

```tsx
import { InterstitialAdLoader, Gender } from '@yandex-ads/react-native-yandex-ads';

const loader = await InterstitialAdLoader.create();
const ad = await loader.loadAd({
  adUnitId: 'R-M-XXXXX-YY',
  targeting: {
    age: '25',
    gender: Gender.Male,
  },
});
```

同样适用于 `RewardedAdLoader` 和 `AppOpenAdLoader`。

## 3. 将 `adUnitId` 从 `BannerView` 属性移至 `adRequest`

`adUnitId` 属性已从 `BannerView` 中移除。 广告单元 ID 现在是 `adRequest` 内的必填字段。

**需要执行的操作**: 移除 `adUnitId` 属性，并设置 `adRequest.adUnitId`。

#### 之前

```tsx
<BannerView
  adUnitId="R-M-XXXXX-YY"
  size={adSize}
/>
```

#### 之后

```tsx
<BannerView
  size={adSize}
  adRequest={{ adUnitId: 'R-M-XXXXX-YY' }}
/>
```

## 4. 将定位移至`定位`对象

`age`、`gender`、`location`、`contextQuery` 和 `contextTags` 嵌套在 `targeting`（针对全屏格式）和 `BannerView` 下。

**需要执行的操作**: 将这些字段包装在 `targeting: { ... }` 中。

### 全屏广告（插屏广告、激励广告、开屏广告）

#### 之前

```ts
loader.loadAd({
  adUnitId: 'R-M-XXXXX-YY',
  age: '25',
  gender: Gender.Male,
  contextTags: ['sport', 'news'],
});
```

#### 之后

```tsx
loader.loadAd({
  adUnitId: 'R-M-XXXXX-YY',
  targeting: {
    age: '25',
    gender: Gender.Male,
    contextTags: ['sport', 'news'],
  },
});
```

### `BannerView`

#### 之前

```tsx
import { Gender } from '@yandex-ads/react-native-yandex-ads';

<BannerView
  adUnitId="R-M-XXXXX-YY"
  size={adSize}
  adRequest={{ age: '25', gender: Gender.Male }}
/>
```

#### 之后

```tsx
import { Gender } from '@yandex-ads/react-native-yandex-ads';

<BannerView
  size={adSize}
  adRequest={{ adUnitId: 'R-M-XXXXX-YY', targeting: { age: '25', gender: Gender.Male } }}
/>
```

## 5. 新增 `AdInfo` 界面

版本 8.0.0 添加了 `AdInfo`，其中包含已加载广告的元数据。

```ts
interface AdInfo {
  adUnitId: string;
  extraData?: string;
  partnerText?: string;
  creatives: Creative[];
}

interface Creative {
  creativeId?: string;
  campaignId?: string;
  placeId?: string;
  offerId?: string;
}
```

### `AdInfo`（针对全屏格式）

`InterstitialAd`、`RewardedAd`、`AppOpenAd` 提供 `adInfo` 取值属性：

```ts
const ad = await loader.loadAd({ adUnitId: 'R-M-XXXXX-YY' });
console.log(ad.adInfo?.adUnitId);
console.log(ad.adInfo?.creatives);
```

### `BannerView` 中的 `AdInfo`

`onAdLoaded` 接收带有 `adInfo` 的事件：

```tsx
<BannerView
  size={adSize}
  adRequest={{ adUnitId: 'R-M-XXXXX-YY' }}
  onAdLoaded={(event) => {
    const adInfo = event.nativeEvent.adInfo;
    console.log(adInfo?.adUnitId);
  }}
/>
```

## 6. 版本要求

### iOS

- **Xcode**：16.4 或更高版本。
- **AppMetricaCore**：6.0.0 或更高版本。
- **AppMetricaLibraryAdapter**：6.0.0 或更高版本。
- **AppMetricaAdSupport**：6.0.0 或更高版本。
- **AppMetricaIDSync**：6.0.0 或更高版本。

### Android

- **Gradle**：7.0 或更高版本。
- **Android Gradle 插件**：8.3.2 或更高版本。
- **Android SDK**：API 21 (Android 5.0) 或更高版本。
- **Kotlin**：1.9.0 或更高版本。
- **Java**：8 或更高版本。
