revenuecat
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRevenueCat Skill
RevenueCat Skill
Expert assistance for implementing in-app subscriptions and purchases using RevenueCat across iOS, Android, Flutter, React Native, and web platforms.
为iOS、Android、Flutter、React Native及Web平台提供基于RevenueCat的内购订阅与购买实现的专业协助。
When to Use This Skill
何时使用本技能
This skill should be triggered when:
- SDK Setup: Initializing RevenueCat SDK in iOS, Android, Flutter, or React Native apps
- Subscription Implementation: Adding subscription or in-app purchase functionality
- Entitlement Checks: Verifying user access to premium features or content
- Purchase Flow: Implementing buy buttons, handling transactions, or processing purchases
- Restore Purchases: Adding restore functionality for users switching devices
- Offerings/Products: Fetching and displaying subscription options or product catalogs
- Paywall Design: Building or configuring paywalls and purchase screens
- Customer Info: Retrieving subscription status or customer data
- Debugging Purchases: Troubleshooting subscription issues or transaction failures
- REST API Integration: Server-side subscription validation or webhook handling
本技能适用于以下场景:
- SDK 配置:在iOS、Android、Flutter或React Native应用中初始化RevenueCat SDK
- 订阅功能实现:添加订阅或内购功能
- 权限验证:验证用户对高级功能或内容的访问权限
- 购买流程开发:实现购买按钮、处理交易或完成购买流程
- 恢复购买:为更换设备的用户添加购买恢复功能
- 产品/套餐管理:获取并展示订阅选项或产品目录
- 付费墙设计:构建或配置付费墙与购买界面
- 用户信息获取:检索订阅状态或用户数据
- 购买问题调试:排查订阅问题或交易失败原因
- REST API 集成:服务端订阅验证或Webhook处理
Quick Reference
快速参考
SDK Configuration
SDK 配置
Swift (iOS)
swift
import RevenueCat
Purchases.logLevel = .debug
Purchases.configure(withAPIKey: "your_public_api_key", appUserID: "user_123")Kotlin (Android)
kotlin
Purchases.logLevel = LogLevel.DEBUG
Purchases.configure(PurchasesConfiguration.Builder(this, "your_public_api_key").build())Flutter
dart
await Purchases.setLogLevel(LogLevel.debug);
PurchasesConfiguration configuration = PurchasesConfiguration("your_public_api_key");
await Purchases.configure(configuration);React Native
javascript
Purchases.setLogLevel(Purchases.LOG_LEVEL.DEBUG);
Purchases.configure({ apiKey: "your_public_api_key" });Swift (iOS)
swift
import RevenueCat
Purchases.logLevel = .debug
Purchases.configure(withAPIKey: "your_public_api_key", appUserID: "user_123")Kotlin (Android)
kotlin
Purchases.logLevel = LogLevel.DEBUG
Purchases.configure(PurchasesConfiguration.Builder(this, "your_public_api_key").build())Flutter
dart
await Purchases.setLogLevel(LogLevel.debug);
PurchasesConfiguration configuration = PurchasesConfiguration("your_public_api_key");
await Purchases.configure(configuration);React Native
javascript
Purchases.setLogLevel(Purchases.LOG_LEVEL.DEBUG);
Purchases.configure({ apiKey: "your_public_api_key" });Checking Entitlements
权限验证
Swift
swift
let customerInfo = try await Purchases.shared.customerInfo()
if customerInfo.entitlements["pro"]?.isActive == true {
// User has premium access
}Kotlin
kotlin
Purchases.sharedInstance.getCustomerInfoWith(
onSuccess = { customerInfo ->
if (customerInfo.entitlements["pro"]?.isActive == true) {
// User has premium access
}
}
)React Native
javascript
const customerInfo = await Purchases.getCustomerInfo();
if (customerInfo.entitlements.active["pro"] !== undefined) {
// User has premium access
}Swift
swift
let customerInfo = try await Purchases.shared.customerInfo()
if customerInfo.entitlements["pro"]?.isActive == true {
// User has premium access
}Kotlin
kotlin
Purchases.sharedInstance.getCustomerInfoWith(
onSuccess = { customerInfo ->
if (customerInfo.entitlements["pro"]?.isActive == true) {
// User has premium access
}
}
)React Native
javascript
const customerInfo = await Purchases.getCustomerInfo();
if (customerInfo.entitlements.active["pro"] !== undefined) {
// User has premium access
}Fetching Offerings
获取产品套餐组
Swift
swift
Purchases.shared.getOfferings { (offerings, error) in
if let packages = offerings?.current?.availablePackages {
self.display(packages)
}
}Kotlin
kotlin
Purchases.sharedInstance.getOfferingsWith({ error -> }) { offerings ->
offerings.current?.availablePackages?.let { packages ->
// Display packages
}
}Swift
swift
Purchases.shared.getOfferings { (offerings, error) in
if let packages = offerings?.current?.availablePackages {
self.display(packages)
}
}Kotlin
kotlin
Purchases.sharedInstance.getOfferingsWith({ error -> }) { offerings ->
offerings.current?.availablePackages?.let { packages ->
// Display packages
}
}Making a Purchase
实现购买功能
Swift
swift
Purchases.shared.purchase(package: package) { (transaction, customerInfo, error, userCancelled) in
if customerInfo.entitlements["pro"]?.isActive == true {
// Unlock premium content
}
}Kotlin
kotlin
Purchases.sharedInstance.purchase(
packageToPurchase = aPackage,
onError = { error, userCancelled -> },
onSuccess = { storeTransaction, customerInfo ->
if (customerInfo.entitlements["pro"]?.isActive == true) {
// Unlock premium content
}
}
)Swift
swift
Purchases.shared.purchase(package: package) { (transaction, customerInfo, error, userCancelled) in
if customerInfo.entitlements["pro"]?.isActive == true {
// Unlock premium content
}
}Kotlin
kotlin
Purchases.sharedInstance.purchase(
packageToPurchase = aPackage,
onError = { error, userCancelled -> },
onSuccess = { storeTransaction, customerInfo ->
if (customerInfo.entitlements["pro"]?.isActive == true) {
// Unlock premium content
}
}
)Restoring Purchases
恢复购买
Swift
swift
Purchases.shared.restorePurchases { customerInfo, error in
// Check customerInfo to see if entitlement is now active
}Kotlin
kotlin
Purchases.sharedInstance.restorePurchases(
onError = { error -> },
onSuccess = { customerInfo ->
// Check customerInfo to see if entitlement is now active
}
)Swift
swift
Purchases.shared.restorePurchases { customerInfo, error in
// Check customerInfo to see if entitlement is now active
}Kotlin
kotlin
Purchases.sharedInstance.restorePurchases(
onError = { error -> },
onSuccess = { customerInfo ->
// Check customerInfo to see if entitlement is now active
}
)REST API - Get Customer Info
REST API - 获取用户信息
bash
curl --request GET \
--url https://api.revenuecat.com/v1/subscribers/app_user_id \
--header 'Authorization: Bearer PUBLIC_API_KEY'bash
curl --request GET \
--url https://api.revenuecat.com/v1/subscribers/app_user_id \
--header 'Authorization: Bearer PUBLIC_API_KEY'Key Concepts
核心概念
Entitlements
Entitlements(权限)
A level of access, features, or content that a user is "entitled" to. Most apps use a single entitlement (e.g., "pro"). Created in the RevenueCat dashboard and linked to products. When a product is purchased, its associated entitlements become active.
用户可获得的访问权限、功能或内容等级。大多数应用使用单一权限(如“pro”),需在RevenueCat控制台创建并关联产品。用户购买产品后,其关联的权限将被激活。
Offerings
Offerings(产品套餐组)
The set of products available to a user. Configured remotely in the dashboard, allowing you to change available products without app updates. Access via for the default offering.
offerings.current提供给用户的产品集合。可在控制台远程配置,无需更新应用即可变更可用产品。通过获取默认套餐组。
offerings.currentPackages
Packages(产品套餐)
Containers for products within an offering. Include convenience accessors like , , . Each package contains a with pricing details.
.monthly.annual.lifetimestoreProduct套餐组内的产品容器,包含、、等便捷访问器。每个套餐包含带有定价详情的。
.monthly.annual.lifetimestoreProductCustomerInfo
CustomerInfo(用户信息)
The central object containing all subscription and purchase data for a user. Retrieved via or returned after purchases. Contains the dictionary for access checks.
getCustomerInfo()entitlements包含用户所有订阅与购买数据的核心对象。可通过获取或在购买后返回,其中的字典用于权限验证。
getCustomerInfo()entitlementsApp User ID
App User ID(应用用户ID)
Unique identifier for each user. Can be provided during configuration or auto-generated as an anonymous ID. Used to sync purchases across devices.
每个用户的唯一标识符,可在配置时提供或自动生成匿名ID,用于跨设备同步购买记录。
Reference Files
参考文档
This skill includes comprehensive documentation in :
references/- other.md - General RevenueCat documentation and overview
For detailed implementation patterns beyond the quick reference, consult the official documentation at https://www.revenuecat.com/docs/
本技能在目录下包含完整文档:
references/- other.md - RevenueCat通用文档与概述
如需快速参考之外的详细实现方案,请查阅官方文档:https://www.revenuecat.com/docs/
Working with This Skill
本技能使用指南
For Beginners
入门用户
- Start by configuring the SDK in your app's initialization code
- Create entitlements and offerings in the RevenueCat dashboard
- Implement a simple entitlement check before showing premium content
- Add a purchase button using
purchase(package:) - Include a "Restore Purchases" button for App Store compliance
- 在应用初始化代码中配置SDK
- 在RevenueCat控制台创建权限与产品套餐组
- 在展示高级内容前实现简单的权限验证
- 使用添加购买按钮
purchase(package:) - 按照App Store合规要求添加“恢复购买”按钮
For Intermediate Users
中级用户
- Implement dynamic paywalls by fetching offerings and displaying packages
- Handle multiple entitlements for tiered access levels
- Set up customer info listeners for real-time subscription updates
- Use the REST API for server-side validation
- 通过获取套餐组并展示产品套餐实现动态付费墙
- 为分层访问权限处理多权限逻辑
- 设置用户信息监听器以获取实时订阅更新
- 使用REST API实现服务端验证
For Advanced Users
高级用户
- Configure webhooks for server-side event handling
- Implement A/B testing with different offerings
- Set up integrations with analytics and attribution platforms
- Handle edge cases like grace periods and billing retry
- 配置Webhook实现服务端事件处理
- 为不同套餐组实现A/B测试
- 集成分析与归因平台
- 处理宽限期、账单重试等边缘场景
Common Patterns
常见实现模式
Paywall Display Logic
付费墙展示逻辑
swift
// Show paywall only if user doesn't have active subscription
if customerInfo.entitlements["pro"]?.isActive != true {
showPaywall()
}swift
// Show paywall only if user doesn't have active subscription
if customerInfo.entitlements["pro"]?.isActive != true {
showPaywall()
}Conditional Offerings
条件化产品套餐组
swift
if user.isPaidDownload {
packages = offerings?.offering(identifier: "paid_download_offer")?.availablePackages
} else {
packages = offerings?.current?.availablePackages
}swift
if user.isPaidDownload {
packages = offerings?.offering(identifier: "paid_download_offer")?.availablePackages
} else {
packages = offerings?.current?.availablePackages
}Important Notes
重要注意事项
- Always initialize the SDK early in your app's lifecycle
- Use debug logging during development ()
Purchases.logLevel = .debug - The SDK automatically finishes/acknowledges transactions
- Only call from user interaction (like a button tap)
restorePurchases - Use public API keys from Project Settings; never expose secret keys
- Test Store allows development testing without real charges
- 务必在应用生命周期早期初始化SDK
- 开发阶段启用调试日志()
Purchases.logLevel = .debug - SDK会自动完成/确认交易
- 仅通过用户交互(如按钮点击)调用
restorePurchases - 使用项目设置中的公开API密钥,切勿暴露密钥
- 可使用测试商店进行开发测试,无需实际扣费
Resources
资源
Official Documentation
官方文档
- Getting Started: https://www.revenuecat.com/docs/getting-started/quickstart
- SDK Reference: https://www.revenuecat.com/docs/
- REST API: https://docs.revenuecat.com/reference
references/
references/
Organized documentation extracted from official sources with detailed explanations and code examples.
从官方资源提取的结构化文档,包含详细说明与代码示例。
scripts/
scripts/
Add helper scripts here for common automation tasks.
存放用于常见自动化任务的辅助脚本。
assets/
assets/
Add templates, boilerplate, or example projects here.
存放模板、样板代码或示例项目。