revenuecat-entitlements-gate

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

revenuecat-entitlements-gate: check a RevenueCat entitlement

revenuecat-entitlements-gate:检查RevenueCat权限

Use this skill when the user wants to decide whether to show or hide a feature based on an active RevenueCat entitlement. The skill covers the one shot check and the reactive listener; it does not cover purchasing (see
revenuecat-purchase-flow
) or auth (
revenuecat-identify-user
).
当用户希望根据活跃的RevenueCat权限决定是否显示或隐藏某功能时,可使用此技能。该技能涵盖一次性检查和响应式监听,但不包含购买流程(详见
revenuecat-purchase-flow
)或身份验证(详见
revenuecat-identify-user
)。

1. Detect the platform

1. 检测平台

Inspect the working directory and pick the first match, from top to bottom:
  1. React Native:
    package.json
    has a
    react-native-purchases
    entry, or
    react-native
    as a dependency → read
    platforms/react-native.md
    . If
    expo
    is also a dependency, note it as an Expo project.
  2. Flutter:
    pubspec.yaml
    exists at the project root → read
    platforms/flutter.md
    .
  3. Kotlin Multiplatform:
    build.gradle.kts
    contains a
    kotlin { … }
    multiplatform source sets block, or depends on
    com.revenuecat.purchases:purchases-kmp*
    → read
    platforms/kmp.md
    .
  4. Android (native):
    build.gradle(.kts)
    applies
    com.android.application
    (and is not KMP) → read
    platforms/android.md
    .
  5. iOS (native):
    Package.swift
    ,
    *.xcodeproj
    ,
    *.xcworkspace
    , or
    Podfile
    at the project root → read
    platforms/ios.md
    .
If several match (e.g. an
ios/
folder inside a Flutter project), pick the outermost project, the one that owns the build. If still ambiguous, ask the user which platform they want to configure.
检查工作目录,从上到下选择第一个匹配项:
  1. React Native
    package.json
    中包含
    react-native-purchases
    条目,或依赖
    react-native
    → 查看
    platforms/react-native.md
    。若同时依赖
    expo
    ,则标记为Expo项目。
  2. Flutter:项目根目录存在
    pubspec.yaml
    → 查看
    platforms/flutter.md
  3. Kotlin Multiplatform
    build.gradle.kts
    包含
    kotlin { … }
    多平台源码集块,或依赖
    com.revenuecat.purchases:purchases-kmp*
    → 查看
    platforms/kmp.md
  4. Android(原生)
    build.gradle(.kts)
    应用了
    com.android.application
    (且非KMP项目) → 查看
    platforms/android.md
  5. iOS(原生):项目根目录存在
    Package.swift
    *.xcodeproj
    *.xcworkspace
    Podfile
    → 查看
    platforms/ios.md
若存在多个匹配项(例如Flutter项目内包含
ios/
文件夹),选择最外层的项目,即负责构建的项目。若仍有歧义,请询问用户要配置哪个平台。

2. Shared concepts (all platforms)

2. 通用概念(所有平台)

  • Check the entitlement identifier, not the product ID. The identifier (for example
    "premium"
    ) is configured in the RevenueCat dashboard and mapped to one or more products. Using the entitlement lets you change products, prices, and stores without touching app code.
  • customerInfo.entitlements.active
    is the source of truth.
    It is a
    Map<String, EntitlementInfo>
    keyed by entitlement identifier. Presence in
    active
    means the user currently has access. Absence means they do not, regardless of past purchases.
  • Do not gate on purchase history. Expired subscriptions still appear in
    customerInfo.entitlements.all
    but drop out of
    active
    . Use
    active
    only.
  • Fetch once, then subscribe. The first
    customerInfo
    call returns a cached value quickly, and the SDK refreshes in the background. Every SDK exposes a listener or stream that fires when entitlements change (after a purchase, restore, renewal, or expiration). Subscribe to that instead of polling.
  • The SDK must be configured first. If
    Purchases.configure(…)
    has not run, the entitlement call will fail. Set up the SDK via
    integrate-revenuecat
    before using this skill.
  • 检查权限标识符,而非产品ID。标识符(例如
    "premium"
    )在RevenueCat控制台中配置,并映射到一个或多个产品。使用权限标识符可让您无需修改应用代码即可更改产品、价格和商店。
  • customerInfo.entitlements.active
    是唯一可信源
    。它是一个以权限标识符为键的
    Map<String, EntitlementInfo>
    。出现在
    active
    中表示用户当前拥有访问权限;未出现则表示无权限,无论过往购买记录如何。
  • 不要基于购买历史管控权限。已过期的订阅仍会出现在
    customerInfo.entitlements.all
    中,但会从
    active
    中移除。仅使用
    active
    进行判断。
  • 先获取一次,再订阅监听。首次调用
    customerInfo
    会快速返回缓存值,SDK会在后台刷新数据。每个SDK都提供了监听或流,当权限发生变化时(购买、恢复、续订或过期后)会触发。请订阅该监听而非轮询。
  • 必须先配置SDK。若未执行
    Purchases.configure(…)
    ,权限检查调用会失败。使用此技能前,请通过
    integrate-revenuecat
    完成SDK配置。

3. Implementation

3. 实现

Read the platform file that matches detection:
  • platforms/ios.md
  • platforms/android.md
  • platforms/kmp.md
  • platforms/flutter.md
  • platforms/react-native.md
Each platform file shows the one shot check, the reactive subscription, and where to place each in a typical app.
查看与检测结果匹配的平台文件:
  • platforms/ios.md
  • platforms/android.md
  • platforms/kmp.md
  • platforms/flutter.md
  • platforms/react-native.md
每个平台文件展示了一次性检查、响应式订阅的实现方式,以及在典型应用中的放置位置。

4. Verify

4. 验证

Do not claim the gate works until:
  1. A user with an active entitlement sees the gated feature, and a user without it does not.
  2. When the entitlement state changes (test with a sandbox purchase or a manual grant in the dashboard), the UI updates without a manual restart, confirming the listener is wired.
  3. The entitlement identifier in the code matches an identifier that exists in the RevenueCat dashboard. A typo here silently gates everyone out.
在满足以下条件前,请勿确认权限管控功能正常:
  1. 拥有活跃权限的用户能看到受管控的功能,无权限用户则看不到。
  2. 当权限状态变化时(通过沙盒购买或控制台手动授予测试),UI无需手动重启即可更新,确认监听已正确连接。
  3. 代码中的权限标识符与RevenueCat控制台中存在的标识符一致。此处的拼写错误会导致所有用户都无法访问该功能。