This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Expo 年龄范围
一个在 Android 上使用 Play Age Signals API、在 iOS 上使用 Declared Age Range framework 来访问年龄范围信息的库。
重要 此库目前处于 alpha 阶段,并且会频繁出现破坏性变更。
expo-age-range 提供对用户年龄范围信息的访问。它在 Android 上使用 Google 的 Play Age Signals API,在 iOS 上使用 Apple 的 Declared Age Range framework。
此库允许你向应用用户请求年龄范围信息,以帮助你遵守适龄内容相关法规(例如 美国德克萨斯州 的相关要求),并在应用中提供适龄体验。
限制
我们强烈建议你在真机上测试该功能,因为模拟器运行时可能无法按预期工作。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
在 app 配置中进行配置
设置 iOS 项目
要在 iOS 上使用年龄范围 API,你需要使用 Xcode 26.0 或更高版本构建项目。需要 com.apple.developer.declared-age-range entitlement。将其添加到你的 app config 文件中:
Are you using this library in an existing React Native app?
对于现有的 React Native 项目,请将该 entitlement 添加到项目的 ios/[app]/[app].entitlements 文件中:
<key>com.apple.developer.declared-age-range</key> <true/>
使用
其他资源
- Play Age Signals API:Android 年龄信号文档
- Declared Age Range framework:iOS 声明年龄范围文档
API
import * as AgeRange from 'expo-age-range';
Methods
Prompts the user to share their age range with the app. Responses may be cached by the OS for future requests.
Promise<AgeRangeResponse>A promise that resolves with user's age range response, or rejects with an error.
The user needs to be signed in on the device to get a valid response.
When not supported (earlier than iOS 26 and web), the call returns lowerBound: 18, which is equivalent to the response of an adult user.
Types
Response containing the user's age range information.
Contains age boundaries and platform-specific metadata.
错误代码
可在原生模块抛出的任何错误的 code 属性中找到。有关 Android 特定错误代码,请参阅 Play Age Signals API 文档 中的“处理 API 错误代码”。