调用SKPaymentQueue restoreCompletedTransactions,无响应 [英] Calling SKPaymentQueue restoreCompletedTransactions, no response

查看:352
本文介绍了调用SKPaymentQueue restoreCompletedTransactions,无响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里的用例是用户从未购买过我的应用内购买商品,而是点击恢复"按钮.我想让用户知道还原失败,因为没有要还原的内容.

The use case here is that the user has never purchased my in-app purchase but taps the Restore button. I want to let the user know that the restore has failed because there is nothing to restore.

问题是我没有任何事件.所以我不知道发生了什么事.

The problem is that I'm not getting any event. So I don't know that anything has happened.

当我的用户点击界面中的还原"按钮时,我会致电

When my user taps the Restore button in my interface, I call

SKPaymentQueue.default().restoreCompletedTransactions

但是,此后没有任何反应.我希望我的SKPaymentTransactionObserver paymentQueue(_:updatedTransactions:)被调用,但不是.

However, after that nothing is happening. I expect my SKPaymentTransactionObserver paymentQueue(_:updatedTransactions:) to be called, but it isn't.

我尝试实现paymentQueue(_:restoreCompletedTransactionsFailedWithError:),但是也没有被调用.

I tried implementing paymentQueue(_:restoreCompletedTransactionsFailedWithError:), but it isn't being called either.

推荐答案

您是如此亲密!您需要实现以下SKPaymentTransactionObserver方法:

You're so close! You need to implement this SKPaymentTransactionObserver method:

func paymentQueueRestoreCompletedTransactionsFinished(_ queue: SKPaymentQueue) {
    // ...
}

如果设备能够与App Store通信,则在restoreCompletedTransactions之后调用该方法-无论还原是由于用户确实有购买要恢复而成功还是因用户没有购买要恢复而失败了

That method is called after restoreCompletedTransactions, if the device was able to communicate with the App Store — regardless of whether the restore succeeded because the user did indeed have purchases to restore, or failed because the user had no purchases to restore.

不幸的是,您在这里没有获得任何有关刚刚发生的事情的信息.我认为这是StoreKit架构中的缺陷.

Unfortunately, you don't get any information here about what just happened. I regard that as a flaw in the StoreKit architecture.

但是,如果还原成功,我们将通过paymentQueue(_:updatedTransactions:),且transactionState.restored.因此,大概是您要设置某种UserDefaults Bool(或类似名称)以表明用户已经购买了该产品.

However, if the restore succeeded, we will have passed through paymentQueue(_:updatedTransactions:) with a transactionState of .restored. So presumably you are setting some sort of UserDefaults Bool (or similar) to indicate that the user has made this purchase.

好吧,这是在 paymentQueueRestoreCompletedTransactionsFinished被调用之前发生或没有发生的情况.因此,在paymentQueueRestoreCompletedTransactionsFinished中,您可以查看是否设置了UserDefaults Bool,如果未设置,则可以猜测该用户可能一开始就从未进行过任何购买,然后做出相应的响应.

Well, that happens or doesn't happen before paymentQueueRestoreCompletedTransactionsFinished is called. So in paymentQueueRestoreCompletedTransactionsFinished you can look to see whether that UserDefaults Bool is set, and if it isn't, you can guess that the user probably never made any purchase in the first place, and respond accordingly.

这是猜测,但总比没有好.

It's guesswork, but it's better than nothing.

这篇关于调用SKPaymentQueue restoreCompletedTransactions,无响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆