Flutter SDK 中的儿童模式
如果您的 Flutter 应用面向儿童,则必须遵守 Apple 和 Google 的相关政策。如果您正在使用 Adapty SDK,只需几个简单步骤即可将其配置为符合这些政策,并顺利通过应用商店审核。
需要做什么?
你需要配置 Adapty SDK 以禁止收集以下信息:
- IDFA(广告主标识符)(iOS)
- Android 广告 ID(AAID/GAID)(Android)
- IP 地址
此外,我们建议谨慎使用 customer user ID。以
<FirstName.LastName>格式设置的 User ID 与使用邮箱地址一样,会被认定为收集个人数据。在儿童模式下,最佳做法是使用随机化或匿名化的标识符(例如哈希 ID 或设备生成的 UUID),以确保合规。
启用儿童模式
在 Adapty 看板中进行更新
在 Adapty 看板中,您需要禁用 IP 地址收集。为此,请前往 App settings,然后在 Collect users’ IP address 下点击 Disable IP address collection。
更新您的移动应用代码
为了遵守相关政策,请禁用用户 IDFA(iOS)、GAID/AAID(Android)以及 IP 地址的收集。
Android:更新 SDK 配置
try {
await Adapty().activate(
configuration: AdaptyConfiguration(apiKey: 'YOUR_API_KEY')
..withGoogleAdvertisingIdCollectionDisabled(true) // set to `true`
..withIpAddressCollectionDisabled(true), // set to `true`
);
} catch (e) {
// handle the error
}
iOS:在 SDK v4 中启用儿童模式
在 SDK v4 中,原生 iOS SDK 通过 Swift Package Manager 安装,儿童模式通过 KidsMode Swift 包 trait 启用,该 trait 会在编译时移除所有 IDFA、AdSupport 和 AppTrackingTransparency 相关代码。此功能需要 Xcode 26 或更高版本。
在 SDK v4 中,请在 pubspec.yaml 中使用 adapty_flutter_kids 包替代 adapty_flutter。这是该插件的儿童模式变体,具有相同的公共 API 和相同的版本号——唯一的区别是其原生 iOS SDK 使用 KidsMode trait 构建:
dependencies:
adapty_flutter_kids: 4.0.0
您的 Dart 代码保持不变——只需将 import 更新为新的包名:
iOS:通过 CocoaPods 启用儿童模式(SDK v3)
-
更新您的 Podfile:
- 如果您没有
post_install部分,请添加下面的完整代码块。 - 如果您已有
post_install部分,请将高亮行合并进去。
def adapty_enable_kids_mode(installer) installer.pods_project.targets.each do |target| next unless target.name == 'Adapty' target.build_configurations.each do |config| flags = config.build_settings['OTHER_SWIFT_FLAGS'] || '$(inherited)' flags = flags.join(' ') if flags.is_a?(Array) config.build_settings['OTHER_SWIFT_FLAGS'] = "#{flags} -DADAPTY_KIDS_MODE" end target.frameworks_build_phase.files.dup.each do |bf| target.frameworks_build_phase.remove_build_file(bf) if bf.display_name.to_s.include?('AdSupport') end end installer.pods_project.save Dir.glob(File.join(installer.sandbox.root, 'Target Support Files', '**', '*.xcconfig')).each do |xc| File.write(xc, File.read(xc).gsub(/\s*-framework\s+"?AdSupport"?/, '')) end end post_install do |installer| # ... keep your existing post_install body (Flutter adds one automatically) ... adapty_enable_kids_mode(installer) # <-- enable Adapty Kids Mode end - 如果您没有
-
运行以下命令以应用更改
pod install