---
title: "Capacitor SDK 中的儿童模式"
description: "轻松启用儿童模式以符合 Apple 和 Google 政策。Capacitor SDK 中不收集 IDFA、GAID 或广告数据。"
---

如果您的 Capacitor 应用面向儿童用户，您必须遵守 [Apple](https://developer.apple.com/kids/) 和 [Google](https://support.google.com/googleplay/android-developer/answer/9893335) 的相关政策。如果您正在使用 Adapty SDK，只需几个简单步骤即可完成配置，以满足这些政策要求并通过应用商店审核。

## 需要做什么？ \{#whats-required\}

您需要配置 Adapty SDK，禁止收集以下信息：

- [IDFA（广告标识符）](https://en.wikipedia.org/wiki/Identifier_for_Advertisers)（iOS）
- [Android 广告 ID（AAID/GAID）](https://support.google.com/googleplay/android-developer/answer/6048248)（Android）
- [IP 地址](https://www.ftc.gov/system/files/ftc_gov/pdf/p235402_coppa_application.pdf)

此外，我们建议谨慎使用自定义用户 ID。格式为 `<FirstName.LastName>` 的用户 ID 以及电子邮件地址，都会被视为收集个人数据。在儿童模式下，最佳实践是使用随机化或匿名化的标识符（例如哈希 ID 或设备生成的 UUID），以确保合规性。

## 启用儿童模式 \{#enabling-kids-mode\}

### 在 Adapty 看板中进行更新 \{#updates-in-the-adapty-dashboard\}

在 Adapty 看板中，您需要禁用 IP 地址收集。为此，请前往 [App settings](https://app.adapty.io/settings/general)，然后在 **Collect users' IP address** 下点击 **Disable IP address collection**。

### 在您的移动应用代码中进行更新 \{#updates-in-your-mobile-app-code\}

为了符合相关政策，请禁用用户 IDFA、GAID 和 IP 地址的收集：

```typescript showLineNumbers

try {
  await adapty.activate({
    apiKey: 'YOUR_PUBLIC_SDK_KEY',
    params: {
      // Disable IP address collection
      ipAddressCollectionDisabled: true,
      
      // Disable IDFA collection on iOS
      ios: {
        idfaCollectionDisabled: true
      },
      
      // Disable Google Advertising ID collection on Android
      android: {
        adIdCollectionDisabled: true
      }
    }
  });
  console.log('Adapty activated with Kids Mode enabled');
} catch (error) {
  console.error('Failed to activate Adapty with Kids Mode:', error);
}
```

### 平台特定配置 \{#platform-specific-configurations\}

#### iOS：使用 CocoaPods 启用儿童模式 \{#ios-enable-kids-mode-using-cocoapods\}

如果您在 iOS 上使用 CocoaPods，也可以在原生层面启用儿童模式：

1. 更新您的 Podfile：

   - 如果您**没有** `post_install` 部分，请添加以下完整代码块。
   - 如果您**已有** `post_install` 部分，请将高亮行合并到其中。

   ```ruby showLineNumbers title="Podfile"
   post_install do |installer|
     installer.pods_project.targets.each do |target|
       # highlight-start
       if target.name == 'Adapty'
         target.build_configurations.each do |config|
           config.build_settings['OTHER_SWIFT_FLAGS'] ||= ['$(inherited)']
           config.build_settings['OTHER_SWIFT_FLAGS'] << '-DADAPTY_KIDS_MODE'
         end
       end
       # highlight-end
     end
   end
   ```

2. 运行以下命令以应用更改：

   ```sh showLineNumbers title="Shell"
   pod install 
   ```

#### Android：使用 Gradle 启用儿童模式 \{#android-enable-kids-mode-using-gradle\}

对于 Android，您也可以通过在应用的 `build.gradle` 中添加以下内容，在原生层面启用儿童模式：

```groovy showLineNumbers title="android/app/build.gradle"
android {
    defaultConfig {
        // ... existing config ...
        
        // Enable Kids Mode
        buildConfigField "boolean", "ADAPTY_KIDS_MODE", "true"
    }
}
```

## 后续步骤 \{#next-steps\}

启用儿童模式后，请确保：

1. 全面测试您的应用，确保所有功能正常运行
2. 更新应用的隐私政策，以反映已禁用的数据收集内容
3. 在提交应用审核时，提供有关儿童模式合规性的清晰说明文档

有关平台特定要求的更多信息：
- [iOS SDK 中的儿童模式](kids-mode)，了解更多 iOS 配置详情
- [Android SDK 中的儿童模式](kids-mode-android)，了解更多 Android 配置详情