如果删除应用程序会清除所有交易数据,如何测试在 Xcode Storekit 沙箱中恢复购买?

问题描述 投票:0回答:1

Xcode 14 中的沙箱环境让我感到困惑。

我正在尝试测试以下场景:

  • 用户进行应用内购买(非消耗品)
  • 用户删除应用程序
  • 用户重新安装应用程序
  • 用户按下恢复购买

应用程序被删除后,它会清除“调试”>“Storekit”中的所有沙盒交易数据。

那么,当我重新编译应用程序时没有可检索的数据时,如何测试这种情况?

swift xcode storekit
1个回答
0
投票

每次用户启动您的应用程序时,您都可以使用 Transaction 的

currentEntitlements
属性来恢复他们的购买,如以下 apple 文档中的代码所示

func refreshPurchasedProducts() async {
    // Iterate through the user's purchased products.
    for await verificationResult in Transaction.currentEntitlements {
        switch verificationResult {
        case .verified(let transaction):
            // Check the type of product for the transaction
            // and provide access to the content as appropriate.
            ...
        case .unverified(let unverifiedTransaction, let verificationError):
            // Handle unverified transactions based on your
            // business model.
            ...
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.