---
title: "在纯 React Native 项目中使用备用付费墙"
description: "在纯 React Native（非 Expo）项目中配置备用付费墙。"
---

:::important
本指南适用于**纯 React Native（非 Expo）项目**。
如果你使用的是 **Expo**，请参阅 [Expo 备用付费墙指南](react-native-use-fallback-paywalls-expo)。
:::

为了保持流畅的用户体验，请务必为您的流程、[付费墙](paywalls)和[用户引导](onboardings)设置[备用方案](/fallback-paywalls)。这一预防措施可以在网络部分或完全中断时，确保应用仍能正常运行。

* **若应用无法访问 Adapty 服务器：**

    应用可以显示备用流程或付费墙，并读取本地的用户引导配置。

* **若应用无法访问互联网：**

    应用可以显示备用流程或付费墙。用户引导包含远程内容，需要联网才能正常使用。

:::important
在按照本指南操作之前，请先从 Adapty [下载](/local-fallback-paywalls)备用配置文件。
:::
## 配置 \{#configuration\}
### Android

1. 将备用配置文件添加到您的应用程序中。选择以下目录之一：
   * **android/app/src/main/assets/**
   * **android/app/src/main/res/raw/**

      注意：`res/raw` 文件夹有特殊的文件命名规范（必须以字母开头，不能使用大写字母，不能使用下划线以外的特殊字符，文件名中不能有空格）。
2. 更新 `FileLocation` 常量的 `android` 属性：
   * 如果文件位于 `assets` 目录下，传入文件相对于该目录的路径。
   * 如果文件位于 `res/raw` 目录下，传入不含扩展名的文件名。
### iOS

1. 将备用 JSON 文件添加到项目包中：在 XCode 中打开 **File** 菜单，选择 **Add Files to "YourProjectName"** 选项。
2. 将配置文件的名称传递给 `FileLocation` 常量的 `ios` 属性。
## 示例 \{#example\}
<Tabs groupId="current-os" queryString> <TabItem value="current" label="Current (v3.8+)" default>
```typescript showLineNumbers
//after v3.8
const fileLocation = {
  ios: {
    fileName: 'ios_fallback.json'
  },
  android: {
    //if the file is located in 'android/app/src/main/assets/'
    relativeAssetPath: 'android_fallback.json'
  }
}
await adapty.setFallback(fileLocation);
```
</TabItem>
<TabItem value="old" label="Legacy (before v3.8)">
```typescript showLineNumbers
//Legacy (before v3.8)
const paywallsLocation = {
  ios: {
    fileName: 'ios_fallback.json'
  },
  android: {
    //if the file is located in 'android/app/src/main/assets/'
    relativeAssetPath: 'android_fallback.json'
  }
}
await adapty.setFallbackPaywalls(paywallsLocation);
```
</TabItem>
</Tabs>
| 参数 | 描述 |
| :------------------- | :------------------------------------------------------- |
| **fileLocation** | 表示备用配置文件位置的对象。 |