gpt4 book ai didi

ios - SKPaymentQueue updatedTransactions 未被调用

转载 作者:IT王子 更新时间:2023-10-29 05:24:23 34 4
gpt4 key购买 nike

我收到“此应用程序内购买已购买,它将免费恢复”但未调用代理 updatedTransactions 并且没有任何反应,IAP 未执行。

我已经实现了 Restore Purchase,它运行良好,但我如何防止用户再次购买非消耗品?为什么没有调用委托(delegate) updatedTransactions(SKPaymentTransactionState.Restored)?

即使在删除并重新安装应用程序后进行购买也会显示此弹出窗口。

这是我的代码。如果我做错了什么请告诉我。谢谢

func makePaymentForProduct(product:SKProduct){
let payment = SKPayment.init(product: product)
SKPaymentQueue.defaultQueue().addPayment(payment)
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}

func restorePurchases(){
SKPaymentQueue.defaultQueue().restoreCompletedTransactions()
SKPaymentQueue.defaultQueue().addTransactionObserver(self)
}


//MARK: SKProductsRequestDelegate

func productsRequest(request: SKProductsRequest, didReceiveResponse response: SKProductsResponse) {
self.delegate?.didGetProducts(response.products)
}

func request(request: SKRequest, didFailWithError error: NSError) {
self.delegate?.purchaseFailed(error.localizedDescription)
}

//MARK: SKPaymentTransactionObserver

func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) {

for (_, transaction) in transactions.enumerate() {
switch (transaction.transactionState) {
case SKPaymentTransactionState.Purchased:
self.completeTransaction(transaction)
break
case SKPaymentTransactionState.Restored:
self.restoreTransaction(transaction)
break
case SKPaymentTransactionState.Failed:
self.failedTransaction(transaction)
break
default:
break
}
}
}

func completeTransaction(transaction:SKPaymentTransaction){
self.delegate?.purchaseSuccessful()
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
}

func restoreTransaction(transaction:SKPaymentTransaction){
self.delegate?.purchaseSuccessful()
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
}

func failedTransaction(transaction:SKPaymentTransaction){
self.delegate?.purchaseFailed("")
SKPaymentQueue.defaultQueue().finishTransaction(transaction)
}


//Restore Purchase

func paymentQueueRestoreCompletedTransactionsFinished(queue: SKPaymentQueue) {
self.delegate?.purchaseRestored()
}

func paymentQueue(queue: SKPaymentQueue, restoreCompletedTransactionsFailedWithError error: NSError) {
self.delegate?.purchaseFailed(error.localizedDescription)
}

最佳答案

您在 调用 .restoreCompletedTransactions() 后设置事务观察器,这可能是问题所在 - 我建议您尝试

func restorePurchases(){
SKPaymentQueue.default().add(self)
SKPaymentQueue.default().restoreCompletedTransactions()
}

而不是上面的实现。

作为旁注,我看到您的原始代码在多个位置添加了事务观察器 - 您可能会考虑尝试将其减少到一个位置(如果可能的话!)。

关于ios - SKPaymentQueue updatedTransactions 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37362244/

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