突然不再使用 StoreKit 获得正确的 transactionIdentifier

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

几天后,我注意到我的应用内购买流程似乎被破坏了。恢复的 transactionID 始终是从 0 开始并递增的单个数字。通常每笔交易都是一个非常大的唯一数字,但不知何故,这里的情况并非如此。我没有更改代码中的任何内容,如下所示:

func purchaseProduct(_ product: Product, completion: @escaping (Bool) -> Void) {
        let payment = SKPayment(product: product.skProduct)
        SKPaymentQueue.default().add(self)
        SKPaymentQueue.default().add(payment)
        purchaseStatus = .pending
        purchaseCompletion = completion
    }

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {
        for transaction in transactions {
            print(transaction)
            switch transaction.transactionState {
            case .purchased:
                print(transaction.transactionIdentifier) // this is not proper
               
                SKPaymentQueue.default().finishTransaction(transaction)
                DispatchQueue.main.async {
                    self.purchaseStatus = .success
                }
                resetPurchaseStatus()
            case .failed:
                // Handle failed purchase
                if let error = transaction.error {
                    DispatchQueue.main.async {
                        self.purchaseStatus = .failure(error)
                    }
                }
                SKPaymentQueue.default().finishTransaction(transaction)
                resetPurchaseStatus()
            case .restored:
                // Handle restored purchases
                SKPaymentQueue.default().finishTransaction(transaction)
                DispatchQueue.main.async {
                    self.purchaseStatus = .success
                }
                resetPurchaseStatus()
            default:
                break
            }
        }
    }

有人有过这样的经历吗?

ios swift in-app-purchase storekit
1个回答
0
投票

在这种特殊情况下,似乎是与我的调试配置关联的 StoreKit 文件存在问题。这会导致事务 ID 按顺序生成(从 0 开始)。删除文件,从而切换回正确的沙箱环境,似乎已经解决了问题。

© www.soinside.com 2019 - 2024. All rights reserved.