当前位置:首页>iOSAPP>iOS 使用 StoreKit Configuration File 在开发阶段测试会员购买功能

iOS 使用 StoreKit Configuration File 在开发阶段测试会员购买功能

  • 2026-09-04 06:51:54
iOS 使用 StoreKit Configuration File 在开发阶段测试会员购买功能

创建 StoreKit Configuration 文件用于本地测试内购功能。

确认了产品 ID:

  • SpeechNote.Membership.Monthly - 月度会员
  • SpeechNote.Membership.Yearly - 年度会员
  • SpeechNote.Membership.Lifetime - 终身会员

现在创建 StoreKit Configuration 文件。

Products.storekit:

{
  "identifier" : "7A3F8B2E-1234-5678-9ABC-DEF012345678",
  "nonRenewingSubscriptions" : [

  ],
  "products" : [
    {
      "displayPrice" : "298",
      "familyShareable" : false,
      "internalID" : "lifetime_001",
      "localizations" : [
        {
          "description" : "一次购买,永久使用所有高级功能",
          "displayName" : "终身会员",
          "locale" : "zh_CN"
        },
        {
          "description" : "One-time purchase, lifetime access to all premium features",
          "displayName" : "Lifetime Membership",
          "locale" : "en_US"
        }
      ],
      "productID" : "SpeechNote.Membership.Lifetime",
      "referenceName" : "Lifetime Membership",
      "type" : "NonConsumable"
    }
  ],
  "settings" : {
    "_applicationInternalID" : "1234567890",
    "_developerTeamID" : "ABCD1234EF",
    "_failTransactionsEnabled" : false,
    "_locale" : "zh_CN",
    "_storefront" : "CHN",
    "_storeKitErrors" : [
      {
        "current" : null,
        "enabled" : false,
        "name" : "Load Products"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "Purchase"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "Verification"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "App Store Sync"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "Subscription Status"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "App Transaction"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "Manage Subscriptions Sheet"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "Refund Request Sheet"
      },
      {
        "current" : null,
        "enabled" : false,
        "name" : "Offer Code Redeem Sheet"
      }
    ]
  },
  "subscriptionGroups" : [
    {
      "id" : "group_speechnote_membership",
      "localizations" : [
        {
          "description" : "SpeechNote Pro 会员订阅",
          "displayName" : "SpeechNote Pro",
          "locale" : "zh_CN"
        },
        {
          "description" : "SpeechNote Pro Membership Subscription",
          "displayName" : "SpeechNote Pro",
          "locale" : "en_US"
        }
      ],
      "name" : "SpeechNote Membership",
      "subscriptions" : [
        {
          "adHocOffers" : [

          ],
          "codeOffers" : [

          ],
          "displayPrice" : "18",
          "familyShareable" : false,
          "groupNumber" : 1,
          "internalID" : "monthly_001",
          "introductoryOffer" : {
            "displayPrice" : "0",
            "internalID" : "monthly_intro_001",
            "numberOfPeriods" : 1,
            "paymentMode" : "free",
            "subscriptionPeriod" : "P3D"
          },
          "localizations" : [
            {
              "description" : "每月订阅 SpeechNote Pro,随时可取消",
              "displayName" : "月度会员",
              "locale" : "zh_CN"
            },
            {
              "description" : "Monthly subscription to SpeechNote Pro, cancel anytime",
              "displayName" : "Monthly Membership",
              "locale" : "en_US"
            }
          ],
          "productID" : "SpeechNote.Membership.Monthly",
          "recurringSubscriptionPeriod" : "P1M",
          "referenceName" : "Monthly Membership",
          "subscriptionGroupID" : "group_speechnote_membership",
          "type" : "RecurringSubscription"
        },
        {
          "adHocOffers" : [

          ],
          "codeOffers" : [

          ],
          "displayPrice" : "128",
          "familyShareable" : false,
          "groupNumber" : 2,
          "internalID" : "yearly_001",
          "introductoryOffer" : {
            "displayPrice" : "0",
            "internalID" : "yearly_intro_001",
            "numberOfPeriods" : 1,
            "paymentMode" : "free",
            "subscriptionPeriod" : "P1W"
          },
          "localizations" : [
            {
              "description" : "年度订阅 SpeechNote Pro,比月付节省41%",
              "displayName" : "年度会员",
              "locale" : "zh_CN"
            },
            {
              "description" : "Yearly subscription to SpeechNote Pro, save 41% compared to monthly",
              "displayName" : "Yearly Membership",
              "locale" : "en_US"
            }
          ],
          "productID" : "SpeechNote.Membership.Yearly",
          "recurringSubscriptionPeriod" : "P1Y",
          "referenceName" : "Yearly Membership",
          "subscriptionGroupID" : "group_speechnote_membership",
          "type" : "RecurringSubscription"
        }
      ]
    }
  ],
  "version" : {
    "major" : 3,
    "minor" : 0
  }
}

产品配置包含:

产品Product ID类型价格
月度会员SpeechNote.Membership.Monthly自动续订订阅¥18/月
年度会员SpeechNote.Membership.Yearly自动续订订阅¥128/年
终身会员SpeechNote.Membership.Lifetime非消耗型¥298

额外配置:

  • 订阅组:SpeechNote Membership
  • 月度会员:3天免费试用
  • 年度会员:1周免费试用
  • 中英文本地化支持
  • Storefront 设置为中国区 (CHN)

在 Xcode 中启用

  1. 打开 Scheme 配置

    • 菜单:Product → Scheme → Edit Scheme...(或按 ⌘ + <)
  2. 设置 StoreKit Configuration

    • 左侧选择 Run
    • 点击 Options 标签
    • 在 StoreKit Configuration 下拉菜单中选择 Products.storekit
  3. 运行测试


测试功能

运行应用后,可以通过 Xcode 菜单测试各种场景:

菜单路径功能
Debug → StoreKit → Manage Transactions查看/管理测试交易
Debug → StoreKit → Time Rate加速订阅时间(1秒=1天等)
Debug → StoreKit → Subscription Renewal Rate控制续订频率
Debug → StoreKit → Delete All Transactions清除所有测试交易

常用测试场景:

  • 正常购买流程
  • 订阅续订/过期
  • 恢复购买
  • 退款(在 Manage Transactions 中操作)
  • 购买失败(可在 .storekit 文件设置中启用错误模拟)
Debug → StoreKit → Manage Transactions

真机测试会员订阅示例:

最新文章

随机文章