跳过内容

继续从创建 iOS 订阅组

GitHub

订阅组对于组织和管理 iOS 应用中的多个订阅级别至关重要。了解它们的工作原理对于实现升级、降级和交叉升级功能至关重要。

什么是订阅组?

标题:什么是订阅组?

订阅组是用户可以选择的相关订阅的集合。用户只能在一个组内订阅一个订阅。他们切换订阅时,苹果会自动处理转换。

为什么订阅组很重要

标题:为什么订阅组很重要

订阅组使得

  • 阶梯式定价: 提供基本、优质和极致计划
  • 不同的时长: 每月、年付和终身选项
  • Upgrade/downgrade logic: 订阅变更的自动处理
  • 简化管理: 将相关订阅分组

订阅等级

订阅等级

在一个组内,每个订阅应该按从最高价值(等级1)到最低价值的顺序排列。这个排列决定了订阅变更的分类:

订阅组层级

等级示例

等级示例

等级1 (最高值)

  • 年度高级版 ($99.99/年)
  • 月度最高版 ($19.99/月)

Level 2 (中等值)

  • 年度标准版 ($49.99/年)
  • 月度高级版 ($9.99/月)

Level 3 (最低值)

  • 年度基本版 ($29.99/年)
  • 月度标准版 ($4.99/月)

订阅变更类型

《订阅变更类型》

苹果会根据等级排名自动处理三种订阅变更类型:

从一个 更高等级 的订阅升级(例如,从等级2升级到等级1)

行为:

  • 立即生效 用户收到
  • 按比例退款 __CAPGO_KEEP_0__ __CAPGO_KEEP_0__
  • __CAPGO_KEEP_1__

例如:

// User currently has: Standard Monthly (Level 2)
// User upgrades to: Premium Annual (Level 1)
// Result: Immediate access to Premium, refund for unused Standard time

2. 降级

降级到

更低的 订阅等级(例如,级别 1 → 级别 2)。 行为:

下次续订日期生效

  • 下次续订日期 下次续订日期
  • __CAPGO_KEEP_0__
  • __CAPGO_KEEP_0__

示例:

// User currently has: Premium Annual (Level 1)
// User downgrades to: Standard Monthly (Level 2)
// Result: Premium access continues until annual renewal date, then switches

在同一等级 行为取决于时长:.

不同时长

→ 与 降级 不同时长 → 降级

  • 下次续费日期生效
  • 例如:月度付费(级别1)→年度付费(级别1)

相同时长 → 与 升级

  • 立即生效
  • 例如:付费月度(级别1)→极致月度(级别1)
  1. 前往订阅

    在 App Store Connect 中,选择您的应用并转到 monetize > 订阅.

  2. 创建组

    点击 + 创建一个新的组

  3. 命名组

    为包含的订阅选择一个描述性的名称:

    • “高级访问”
    • “云存储计划”
    • “专业功能”
  4. 添加订阅

    创建组后,添加单独的订阅到其中。每个订阅将有一个等级排名。

  5. 设置等级排名

    按从最高价值(1)到最低价值的顺序排列订阅。考虑:

    • 年度计划通常优先于月度计划
    • 价格更高的等级排在价格更低的等级之上
    • 最终/高级等级排在最高

在您的应用程序中使用

标题:在您的应用程序中使用

原生购买插件自动处理订阅组逻辑:

import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
// Fetch all subscriptions in a group
const { products } = await NativePurchases.getProducts({
productIdentifiers: ['premium_monthly', 'premium_annual', 'ultimate_monthly'],
productType: PURCHASE_TYPE.SUBS,
});
// Display current subscription using StoreKit transactions
const { purchases } = await NativePurchases.getPurchases({
productType: PURCHASE_TYPE.SUBS,
});
const activeSubs = purchases.filter((purchase) => purchase.isActive);
// Detect pending downgrade/cancellation (StoreKit sets willCancel === true)
const pendingChange = purchases.find((purchase) => purchase.willCancel === true);
if (pendingChange) {
console.log('Subscription will stop auto-renewing on', pendingChange.expirationDate);
}
// Purchase (StoreKit handles upgrades/downgrades automatically)
await NativePurchases.purchaseProduct({
productIdentifier: 'premium_annual',
productType: PURCHASE_TYPE.SUBS,
});
// Listen for StoreKit updates (fires on upgrades/downgrades/refunds)
NativePurchases.addListener('transactionUpdated', (transaction) => {
console.log('Subscription updated:', transaction);
});

处理订阅更改

标题:处理订阅更改

检测更改类型

标题:检测更改类型
import { NativePurchases, PURCHASE_TYPE } from '@capgo/native-purchases';
// Get current subscription info
const { purchases } = await NativePurchases.getPurchases({
productType: PURCHASE_TYPE.SUBS,
});
const currentSubscription = purchases.find(
(purchase) => purchase.subscriptionState === 'subscribed',
);
if (currentSubscription) {
// StoreKit reports if user cancelled auto-renew
if (currentSubscription.willCancel) {
console.log(
`User cancelled. Access remains until ${currentSubscription.expirationDate}`,
);
}
if (currentSubscription.isUpgraded) {
console.log('User recently upgraded to this plan.');
}
}
// Listen for automatic upgrades/downgrades
NativePurchases.addListener('transactionUpdated', (transaction) => {
console.log('Subscription changed!', transaction);
if (transaction.subscriptionState === 'revoked') {
revokeAccess();
} else if (transaction.isActive) {
unlockPremiumFeatures();
}
});

用户沟通

用户沟通

始终清晰地说明变化行为:

升级:

“You’ll get immediate access to Premium features. We’ll prorate your current subscription.”

降级:

“You’ll keep Premium access until [renewal date], then switch to Standard.”

跨级别:

“Your plan will change to Annual billing at the next renewal on [date].”

服务器监控

服务器监控

使用 Apple 的 App Store Server Notifications v2 或您的自己的收据验证后端来在您的数据库中反映 StoreKit 的更改。将服务器通知与 transactionUpdated listener so both client and backend stay in sync.

  • 将相关订阅放在同一个组中
  • 不要混合不相关的功能(例如,存储和广告移除)
  • 为不同功能集创建单独的组
  • 更高价格等级 → 更高等级
  • 更高价格等级 → 更高等级
  • 考虑价值,而不是仅仅价格

用户体验

用户体验
  • 清晰显示当前订阅
  • 在组中显示所有可用选项
  • 标明哪些变化立即生效,哪些在续订时生效
  • 方便地在计划之间切换

测试

测试
  • 测试所有升级场景
  • 测试所有降级场景
  • 验证跨级别升级行为
  • 检查 webhook 触发

常见场景

常见场景

场景 1:每月三层计划

场景 1:每月三层计划
Level 1: Ultimate Monthly ($19.99)
Level 2: Premium Monthly ($9.99)
Level 3: Basic Monthly ($4.99)
  • 基本 → 高级:立即升级
  • 高级 → 最终:立即升级
  • 最终 → 高级:在续订时降级
  • 基本 → 最终:立即升级

场景 2:混合时长计划

场景 2:混合时长计划
Level 1: Premium Annual ($99.99/year)
Level 2: Premium Monthly ($9.99/month)
  • 月度 → 年度:交叉升级(续费时)
  • 年度 → 月度:降级(续费时)

场景 3:多层级多时长

场景 3:多层级多时长
Level 1: Ultimate Annual ($199/year)
Level 2: Ultimate Monthly ($19.99/month)
Level 3: Premium Annual ($99/year)
Level 4: Premium Monthly ($9.99/month)
Level 5: Basic Annual ($49/year)
Level 6: Basic Monthly ($4.99/month)

这种设置提供了最大限度的灵活性,同时保持清晰的升级/降级逻辑。

订阅未出现在组中:

  • 确认它已分配到正确的组
  • 检查它至少处于“已准备好提交”状态
  • 确保产品 ID 正确

升级/降级行为错误:

  • 评级排名 (1 = 最高)
  • 验证订阅等级合理
  • 检查等级设置是否正确

来自不同组的产品:

  • 用户可以同时订阅多个组
  • 这是故意的 - 相关产品保持在同一组

getActiveProducts 显示多个订阅:

  • 检查订阅是否在不同组
  • 验证用户不是通过家庭共享订阅
  • 在 App Store Connect 中检查订阅状态

更多资源

更多资源

详细信息请参阅 请参阅苹果官方文档关于订阅组.

继续从创建iOS订阅组

继续从创建iOS订阅组

如果您正在使用 创建iOS订阅组 来规划商店审批和分发,连接它与 使用@capgo/native-purchases 在使用@capgo/native-purchases的原生能力中 @capgo/capacitor-in-app-review 为 @capgo/capacitor-in-app-review 的实现细节 使用 @capgo/capacitor-in-app-review 为 @capgo/capacitor-in-app-review 的原生能力 @capgo/capacitor-native-market 原生市场 为 @capgo/capacitor-native-market 的实现细节, 和 使用 @capgo/capacitor-native-market 为使用 @capgo/capacitor-native-market 的原生能力