Expo AgeRange

一个库,通过 Android 上的 Play Age Signals API 和 iOS 上的 Declared Age Range 框架提供年龄范围信息访问。

Android
iOS
Included in Expo Go
Bundled version:
~0.2.1

重要 该库目前处于 alpha 版本,可能经常出现重大更改。

expo-age-range 提供用户年龄范围信息的访问权限。它在 Android 上使用 Google 的 Play Age Signals API,在 iOS 上使用 Apple 的 Declared Age Range framework

这个库允许你从应用用户那里请求年龄范围信息,以帮助你遵守适龄内容规定(例如在美国德克萨斯州)并在你的应用中提供适合年龄的体验。

🌐 This library allows you to request age range information from your app users to help you comply with age-appropriate content regulations (such as in Texas, USA) and provide age-appropriate experiences in your app.

局限性

🌐 Limitations

我们强烈建议在真实设备上测试功能,因为模拟器运行时可能无法按预期工作。

🌐 We strongly recommend testing the functionality on a real device, as simulator runtimes may not work as expected.

在 Android 上,根据官方 Android 文档,Play Age Signals API(测试版)可能会抛出异常,直到 2026 年 1 月 1 日。从 1 月 1 日起,该 API 将返回实时响应。

🌐 On Android, the Play Age Signals API (beta) may throw an exception until January 1, 2026, as per the official Android documentation. From January 1, the API will return live responses.

安装

🌐 Installation

Terminal
npx expo install expo-age-range

If you are installing this in an existing React Native app, make sure to install expo in your project.

应用配置中的配置

🌐 Configuration in app config

设置 iOS 项目

🌐 Setup iOS project

要在 iOS 上使用年龄范围 API,你需要使用 Xcode 26.0 或更高版本构建项目。需要 com.apple.developer.declared-age-range 权限。将其添加到你的 应用配置 文件中:

🌐 To use the age range API on iOS, you need to build your project with Xcode 26.0 or later. The com.apple.developer.declared-age-range entitlement is required. Add it to your app config file:

app.json
{ "expo": { "ios": { "entitlements": { "com.apple.developer.declared-age-range": true } } } }
Are you using this library in an existing React Native app?

对于现有的 React Native 项目,将权限添加到项目的 ios/[app]/[app].entitlements 文件中:

🌐 For existing React Native projects, add the entitlement to your project's ios/[app]/[app].entitlements file:

<key>com.apple.developer.declared-age-range</key> <true/>

用法

🌐 Usage

Age Range Usage
import * as AgeRange from 'expo-age-range'; import { useState } from 'react'; import { StyleSheet, Text, View, Button } from 'react-native'; export default function App() { const [result, setResult] = useState<AgeRange.AgeRangeResponse | { error: string } | null>(null); const requestAgeRange = async () => { try { const ageRange = await AgeRange.requestAgeRangeAsync({ threshold1: 10, threshold2: 13, threshold3: 18, }); setResult(ageRange); } catch (error) { setResult({ error: error.message }); } }; return ( <View style={styles.container}> <Button title="请求年龄范围" onPress={requestAgeRange} /> {result && ( <Text style={styles.result}> {'error' in result ? `Error: ${result.error}` : `Lower age bound: ${result.lowerBound}`} </Text> )} </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', padding: 20, }, result: { marginTop: 20, fontSize: 16, }, });

其他资源

🌐 Additional resources

应用接口

🌐 API

import * as AgeRange from 'expo-age-range';

Methods

AgeRange.requestAgeRangeAsync(options)

Android
iOS 26.0+
ParameterType
optionsAgeRangeRequest

Prompts the user to share their age range with the app. Responses may be cached by the OS for future requests.

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

AgeRangeRequest

iOS

Options for requesting age range information from the user.

PropertyTypeDescription
threshold1number

The required minimum age for your app.

threshold2(optional)number

An optional additional minimum age for your app.

threshold3(optional)number

An optional additional minimum age for your app.

AgeRangeResponse

Android
iOS

Response containing the user's age range information.

Contains age boundaries and platform-specific metadata.

PropertyTypeDescription
activeParentalControls(optional)string[]
Only for:
iOS

List of parental controls enabled and shared as a part of age range declaration.

ageRangeDeclaration(optional)'selfDeclared' | 'guardianDeclared'
Only for:
iOS

Indicates whether the age range was declared by the user themselves or someone else (parent, guardian, or Family Organizer in a Family Sharing group).

installId(optional)string
Only for:
Android

An ID assigned to supervised user installs by Google Play, used to notify you of revoked app approval.

lowerBound(optional)number

The lower limit of the person’s age range.

mostRecentApprovalDate(optional)number
Only for:
Android

The effective date (timestamp) of the most recent significant change that was approved.

upperBound(optional)number

The upper limit of the person’s age range.

userStatus(optional)'VERIFIED' | 'SUPERVISED' | 'SUPERVISED_APPROVAL_PENDING' | 'SUPERVISED_APPROVAL_DENIED' | 'UNKNOWN'
Only for:
Android

The user's age verification or supervision status.

错误代码

🌐 Error codes

可在本地模块抛出的任何错误的 code 属性中获取。有关 Android 特定的错误代码,请参见 使用 Play Age Signals API 文档 中的“处理 API 错误代码”。

🌐 Available in the code property of any error thrown by the native module. For Android-specific error codes, see "Handle API error codes" in Use Play Age Signals API docs.

代码平台描述
ERR_AGE_RANGE_USER_DECLINED
iOS
用户拒绝分享他们的年龄范围。
ERR_AGE_RANGE_NOT_AVAILABLE
iOS
年龄范围不可用。最可能的原因是用户未在设备上登录 Apple 账户。
ERR_AGE_RANGE_INVALID_REQUEST
iOS
提供的参数无效。年龄范围之间至少需要相差 2 年。