Calling SKPaymentQueue restoreCompletedTransactions, no response

前端 未结 1 1156
天命终不由人
天命终不由人 2021-01-14 11:34

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

相关标签:
1条回答
  • 2021-01-14 11:57

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

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

    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.

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

    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.

    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.

    0 讨论(0)
提交回复
热议问题