Transaction comes back after finishTransaction: has been called on it

后端 未结 10 1137
一个人的身影
一个人的身影 2020-12-08 15:06

I am using in-app purchase for an iPhone app. I have a class that acts as SKProductsRequestDelegate and SKPaymentTransactionObserver, and it\'s all

10条回答
  •  抹茶落季
    2020-12-08 15:28

    I had this problem too. The bug turned out to be on my side. The problem was that there was a past transaction lurking around that had been executed (the content provided) but not cleaned up using finishTransaction. Unfortunately, on asking at several places including an Apple TSI, I discovered that there was no way to poll such 'undead' transactions - you just had to register for notifications and wait for the corresponding paymentQueue:updatedTransactions:. This complicated my code, but not by much.

    What I do now, which has been working fine:

    • When the store is about to be invoked (you're flashing some marketing slides, a terms of use maybe), fetch your product list and register for notifications as an observer via [[SKPaymentQueue defaultQueue] addTransactionObserver:self]
    • Keep a state variable that gets updated to YES when you push a payment in the queue using [[SKPaymentQueue defaultQueue] addPayment:payment]
    • When you get notified of a successful purchase via paymentQueue:updatedTransactions: check the state variable. If it has not been set, it means you have received a notification for a past payment. In that case, honor that payment rather than pushing a new one.

    This method naturally assumes that you have the time to wait for old transactions to show up before starting a new transaction.

提交回复
热议问题