跳过内容

创建 iOS 订阅组

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

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

订阅组的重要性

标题:订阅组的重要性

订阅组的功能包括:

  • 阶梯式定价: 提供基本、精英和终极计划
  • : 每月、每年和终身选项: 订阅变更的自动处理
  • : 将相关订阅组合在一起的简化管理__CAPGO_KEEP_0__
  • __CAPGO_KEEP_1____CAPGO_KEEP_2__

会员等级

会员等级

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

订阅组层级

等级示例

等级1

(最高价值) 年度高级版 ($99.99/年)

  • 月度极致版 ($19.99/月)
  • 等级2

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

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

等级 3 (最低价值)

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

订阅变更类型

订阅变更类型

苹果会自动处理基于等级排名的三个订阅变更类型:

1. 升级

升级

升级到 高级订阅 降级 (例如, 从 level 2 → level 1).

行为:

  • 立即生效 用户收到
  • 剩余时间的部分退款 新订阅立即开始 示例:
  • 复制到剪贴板

2. 降级

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

降级到 一个较低的 订阅等级(例如,级别 1 → 级别 2)。

行为:

  • 下次续订日期 用户保留当前订阅直到期限结束
  • 新订阅将自动开始在过期后
  • 示例:

复制到剪贴板

// 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)

相同持续时间 → 与 升级

  • 立即生效
  • 例如:Premium Monthly (Level 1) → Ultimate Monthly (Level 1)

创建订阅组

创建订阅组
  1. 转到订阅

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

  2. 创建组

    点击 + 订阅组”旁边的“+”创建新组

  3. 命名组

    选择一个描述性的名称,反映它包含的订阅:

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

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

  5. 设置等级排名

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

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

The native-purchases plugin automatically handles subscription group logic:

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();
}
});

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

升级时:

“您将立即获得高级功能。我们将根据您的当前订阅进行折扣。”

For Downgrades:

“您将保留Premium访问权直到[续费日期],然后切换到标准版。”

For Crossgrades:

“您的计划将在下一次续费时更改为年度计费,于[date]。”

使用Apple的App Store Server Notifications v2或您的自己的收据验证后端来反映StoreKit的更改。将服务器通知与 transactionUpdated listener配对,以便客户端和后端保持同步。

  • 保持相关订阅在同一组
  • 不要混杂无关的功能(例如,存储和广告移除)
  • 为不同功能集创建单独的组

等级排名策略

等级排名策略
  • 年度计划 → 与月度计划相同等级的更高等级
  • 更高价格等级 → 更高等级
  • 考虑价值,而不是仅仅价格

用户体验

用户体验
  • 显示当前订阅
  • 在组中显示所有可用选项
  • 指出哪些变更立即生效 vs. 在续费时生效
  • 允许轻松切换计划
  • 测试所有升级场景
  • 测试所有降级场景
  • 验证跨级别行为
  • 检查 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中检查订阅状态

欲知更多详细信息,请参阅 苹果官方文档关于订阅组.