测试应用内购买 (IAP) - 需要帮助清理交易队列

Testing In-App Purchases (IAP) - Need Help Clearing Transaction Queue

我已经用 IAP 制作了一个应用程序,我在第一次尝试测试它时,我收到了登录提示,但从那以后,我没有收到任何登录提示(我认为这是因为队列中有一个失败的事务)。

我迫切需要帮助来清理交易队列,因为所有这些 IAP 语言对我来说都非常陌生。我在几个地方读到下面的代码片段有效,但老实说我不确定如何正确使用它:

for transaction in SKPaymentQueue.default().transactions {
                guard
                    transaction.transactionState != .purchasing,
                    transaction.transactionState != .deferred
                else {
                    //Optionally provide user feedback for pending or processing transactions
                    return
                }
                //Transaction can now be safely finished
                SKPaymentQueue.default().finishTransaction(transaction)
            }

代码片段终于让登录提示再次出现,但随后我陷入了无休止的登录循环。

下面是我选择放置它的位置,但它目前只是让我在已经登录后立即再次登录.... (新代码片段位于说明 "NEW" 的两个注释行之间)

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { //--------- In App Purchase
        for transaction in transactions{
            //------------------------------------------------------------ New
            for transaction in SKPaymentQueue.default().transactions {
                guard
                    transaction.transactionState != .purchasing,
                    transaction.transactionState != .deferred
                else {
                    //Optionally provide user feedback for pending or processing transactions
                    return
                }
                //Transaction can now be safely finished
                SKPaymentQueue.default().finishTransaction(transaction)
            }
            //------------------------------------------------------------ New
            if transaction.transactionState == .purchased {
                print("Transaction Successful")
                packsUnlocked = true
            } else if transaction.transactionState == .failed {
                print("Transaction Failed with error: \(transaction.error)")
            }
        }

    }

非常感谢您对此提供的任何帮助,因为 Apple 支持只能为我提供非技术支持,而且我已将大量资源投入到此应用程序中,但到最后一步才被搁置。

谢谢

如果不考虑购买交易后的收据验证,那么这里是预期的回调

func paymentQueue(_ queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) { //--------- In App Purchase
        for transaction in transactions {
            guard
                transaction.transactionState != .purchasing,
                transaction.transactionState != .deferred
            else {
                //Optionally provide user feedback for pending or processing transactions
                continue
            }

            if transaction.transactionState == .purchased || transaction.transactionState == .restored {
                print("Transaction Successful")
                packsUnlocked = true
            } else if transaction.transactionState == .failed {
                print("Transaction Failed with error: \(transaction.error)")
            }

            //Transaction can now be safely finished
            queue.finishTransaction(transaction)
        }
    }