Multitasking and SKPaymentQueue I get a “stuck” SKPaymentTransaction with a transactionState of SKPaymentTransactionStatePurchasing

主宰稳场 提交于 2019-12-23 09:50:31

问题


My question is basically how to reproduce the behavior I see in other apps in the app store with regards to in-app purchases:

  • Immediately following the user pressing "Buy" the button is hidden and a spinner is displayed (essentially de-bouncing the Buy action).
  • The user pressing cancel to the StoreKit dialog (in the app or outside of it) results in the spinner going away.

I'm attempting to show and hide the spinner based on observing the state of transactions in the SKPaymentQueue.

My problem is described by this poster:

In App Purchase user cancels tx while app in background: tx state stays on purchasing

I see the same behavior as the post above regardless of if the test user is logged in first or not. The transaction is basically "stuck" in the queue with a purchasing state forever (meaning my spinner is displayed forever). When the app is completely exited and restarted (not just multi-tasked away) the transaction is no longer in the payment queue so it's clearly not really still purchasing. It's like the SKPaymentQueue "missed" the state change.

Some more detail that I've noticed is that in the typical case, immediately after adding the payment, the transaction shows up in the queue with a purchasing state. If the user presses cancel, the state of the transaction goes to failed.

In the case of tasking away immediately after adding the payment, the transaction does not show up in the queue until tasking back to the app. Instead of seeing two calls to the updatedTransactions delegate (one with a state of purchasing and one with a state of failed) there is only one call to the updatedTransactions delegate with a state of purchasing. The transaction never goes to failed.

Very occasionally, when tasking back to the app I will get a transaction removed callback (after seeing the updatedTransaction with a state of purchasing). Even in this case I never see the expected update of the transaction to the failed state.

I am not able to reproduce this behavior in apps in the app store (they always correctly show/hide the spinner regardless of tasking away or not), but it's not clear to me if that's because they are doing something tricky, or if it's only a problem in the sandbox.

How to replicate this behavior if not by monitoring the state of the transaction? Is this not a problem in production?

Thanks!


回答1:


I have used MKStoreKit for all my apps.

It has a block based interface that tells you when the transaction has started (To hide the button and start animating).

It will also tell you if the transaction fails or it was competed, so you can stop the animation and restore the button (if it failed) or show something else when it is completed.

Because it uses blocks, you can handle all this behavior without writing a lot of boilerplate code.



来源:https://stackoverflow.com/questions/8685680/multitasking-and-skpaymentqueue-i-get-a-stuck-skpaymenttransaction-with-a-tran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!