gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 16:12:19 25 4
gpt4 key购买 nike

我已经用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)
}
}

关于ios - 测试应用内购买(IAP)-需要帮助来清除交易队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61838484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com