Reference version

This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 56).

Expo 年龄范围

一个在 Android 上使用 Play Age Signals API、在 iOS 上使用 Declared Age Range 框架来提供年龄范围信息访问的库。

Android
iOS
Included in Expo Go

For the complete documentation index, see llms.txt. Use this file to discover all available pages.

重要 此库目前处于 alpha 阶段,并且会频繁出现破坏性变更。

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

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

限制

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

安装

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.

在 app 配置中进行配置

设置 iOS 项目

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

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 项目,将该 entitlement 添加到项目的 ios/[app]/[app].entitlements 文件中:

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

用法

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="Request Age Range" onPress={requestAgeRange} /> {result && ( <Text style={styles.result}> {'error' in result ? `错误:${result.error}` : `最低年龄下限:${result.lowerBound}`} </Text> )} </View> ); } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', padding: 20, }, result: { marginTop: 20, fontSize: 16, }, });

其他资源

API

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

Methods

AgeRange.getRequiredRegulatoryFeaturesAsync()

iOS 26.4+

Returns the set of regulatory features that the OS reports as required for the current user.

Use this to discover which age-assurance obligations apply.

Resolves with null on iOS earlier than 26.4 and on Android and web — treat null as "unknown" rather than "no features required".

AgeRange.isEligibleForAgeFeaturesAsync()

iOS 26.2+

Asks the OS whether age-assurance regulation applies to the current user. Apple uses this to signal that the account region is covered by a law such as Utah's or Louisiana's age-assurance requirements, so apps can avoid gating users in jurisdictions where the rules do not apply.

  • Resolves with true only when Apple confirms regulation applies.
  • Resolves with false when the OS confirms regulation does not apply.
  • Resolves with null on iOS earlier than 26.2, and on Android and web. Treat null as "unknown" rather than a definitive false.
  • Rejects when the request fails — see AgeRangeService.Error for more information. Treat rejection as "unknown" and fall through to requestAgeRangeAsync or your own gating logic.

Recommended pattern: call this first and only prompt the user for their age range when the result is not false. When it is false, the user is outside a regulated jurisdiction and you can skip the age gate entirely.

Returns:
Promise<boolean | null>

Example

try { const eligible = await isEligibleForAgeFeaturesAsync(); if (eligible === false) { // Regulation does not apply — no age gate needed. return; } } catch { // Treat errors as "unknown" and fall through to the prompt below or your own gating logic. } const ageRange = await requestAgeRangeAsync({ threshold1: 18 });

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.

AgeRange.showSignificantUpdateAcknowledgmentAsync(updateDescription)

iOS 26.4+
ParameterTypeDescription
updateDescriptionstring

A description of the significant update to show to the user.


Displays a system-provided interface for people to acknowledge a significant app update.

Only on iOS 26.4+, this presents an update acknowledgement dialog and resolves once the user confirms it, or rejects with an error. On unsupported platforms this resolves immediately without showing any UI.

Call getRequiredRegulatoryFeaturesAsync first to determine whether the user actually needs to acknowledge a significant change — only invoke this function when the returned features include 'significantAppChangeRequiresAdultNotification'. Doing so avoids prompting users who are not subject to the regulation.

Returns:
Promise<void>

Types

AgeRangeRegulatoryFeature

iOS 26.4+

Literal Type: string

A regulatory feature that your app may need to support for the current user.

Mirrors AgeRangeService.RegulatoryFeature.

Acceptable values are: 'declaredAgeRangeRequired' | 'significantAppChangeRequiresAdultNotification' | 'significantAppChangeRequiresParentalConsent'

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' | null
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 | null
Only for:
Android

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

lowerBoundnumber | null

The lower limit of the person’s age range.

mostRecentApprovalDate(optional)number | null
Only for:
Android

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

upperBoundnumber | null

The upper limit of the person’s age range.

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

The user's age verification or supervision status.

错误代码

可在原生模块抛出的任何错误的 code 属性中获取。有关 Android 特定的错误代码,请参阅 Play Age Signals API 文档 中的 “Handle API error codes”。

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