SKReceiptRefreshRequest 与 restoreCompletedTransactions

SKReceiptRefreshRequest vs restoreCompletedTransactions

我的应用程序使用订阅模式,我收到一些用户无法通过 SKPaymentQueue.restoreCompletedTransactions 恢复订阅的投诉。他们必须删除应用程序并从 AppStore 重新下载。

我不太确定为什么它只发生在某些用户身上,其中一个用户告诉我他通过 iTunes 取消并重新激活,另一个是关于付款问题。

那么为什么他们需要重新下载应用程序?我猜收据上的一些信息没有正确刷新,所以我在考虑使用 SKReceiptRefreshRequest 而不是 restoreCompletedTransactions,或者两者都用。

有人可以解释这两个过程之间的区别吗?

SKReceiptRefreshRequestRestoreCompletedTransactions 之间的区别非常简单:

SKReceiptRefreshRequest

Refreshing the receipt asks the App Store for the latest copy of the receipt. Refreshing a receipt does not create any new transactions. Although you should avoid refreshing multiple times in a row, this action would have same result as refreshing it just once.

RestoreCompletedTransactions

Restoring completed transactions creates a new transaction for every completed transaction the user made, essentially replaying history for your transaction queue observer. While transactions are being restored, your app maintains its own state to keep track of why it’s restoring completed transactions and how it needs to handle them. Restoring multiple times creates multiple restored transactions for each completed transaction.

我们可以同时使用SKReceiptRefreshRequest和恢复已完成的交易来验证用户订阅,但在以下情况下我们必须使用恢复已完成的交易而不是刷新收据:

  • 如果您使用 Apple 托管的内容,恢复已完成的交易会为您的应用提供用于下载内容的交易对象。

  • 如果您需要支持早于 iOS 7 的 iOS 版本,应用收据不可用,请恢复已完成的交易。

  • 如果您的应用使用非续订订阅,您的应用将负责恢复过程。

参考: https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Chapters/Restoring.html#//apple_ref/doc/uid/TP40008267-CH8-SW9