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

gg58donl  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(131)

沙盒环境在Xcode 14中让我感到困惑。
我正在尝试测试以下场景:

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

一旦应用被删除,它会清除Debug > Storekit中的所有沙盒事务数据。
那么,当我重新编译应用程序时,没有数据可供检索时,我如何测试这种情况?

jutyujz0

jutyujz01#

每次用户启动您的应用时,您都可以使用Transaction的currentEntitlements属性从apple documentation恢复其购买,如下面的代码所示。

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.
            ...
        }
    }
}

字符串

相关问题