Closed Bartmax closed 7 years ago
For the first part where would that go?
For the second part I think I do that here: https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs#L110
Sorry for not being clear.
The first part is for the method
public override void UpdatedTransactions(SKPaymentQueue queue, SKPaymentTransaction[] transactions)
For the any of those parts, that handler is not enough. You are creating this handler only for user initiated purchases/restores, (or to see it in another way, only for transactions the app know about). The are many other scenarios the method is called and you can't prepare or create a TaskCompletionSource
. (failed to finalize, deferrer, autorenewal, etc). Those are never finalized. Even if 2 transactions with same productId starts at the same time, the TaskCompletionSource
will return as soon as the first one is done and the other will never finalize.
To avoid any of this, one should not assume that the handler will be called for all transactions, hence why it's proper to have it outside the handler. There's no need to prepare a TaskCompletionSource
because nothing is awaiting this method to finalize. Still one way to notify the application if any of those transaction went successful is desired. I specified that more in deep in https://github.com/jamesmontemagno/InAppBillingPlugin/issues/29
If you have an app using this library on a device for some time already, I suggest you to put a Debug.WriteLine(transaction.TransactionState)
inside the foreach (SKPaymentTransaction transaction in transactions)
. You might be surprised by the output.
So, for the first part I do call FinishTransaction whhen it is completed: https://github.com/jamesmontemagno/InAppBillingPlugin/blob/master/src/Plugin.InAppBilling.iOS/InAppBillingImplementation.cs#L187
Should I just remove that code?
As long as FinishTransaction is called on UpdatedTransactions, yes that code should be removed.
Yeah, basically we now will finish the transaction when purchased or failed regardless if the TransactionCompleted is null or not. That is what this will fix up.
this code should be removed from the handler:
it's already done on the RestoreTransactionCompleted
, i think (not sure) it will throw an exception if you try to finish a finished transaction and with this change you are calling it twice for the same transaction.
Done
The only transactions that are finished right now are user initiated ones.
It's very easy (specially in development) to get unfinished transactions. Also the place in code where the transactions are finished is dangerous, because the library set the transaction as finished BEFORE the application actually did something with them.
the
FinishTransaction
call should be safer to be more like:and