Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Restore to return all products ids at once #18

Closed
mortenholmgaard opened this issue Apr 2, 2016 · 6 comments
Closed

Change Restore to return all products ids at once #18

mortenholmgaard opened this issue Apr 2, 2016 · 6 comments

Comments

@mortenholmgaard
Copy link

Could it be possible to change the Restore method to return all productIds at once?

Sometimes one needs some heavy computation after the restores, but like it is right now, it is not possible to know which callback is the last.

@bizz84
Copy link
Owner

bizz84 commented Apr 3, 2016

I agree that this would be desirable behaviour.

The Apple documentation for SKPaymentQueue.restoreCompletedTransactions() says the following:

The payment queue will deliver a new transaction for each previously completed transaction that can be restored. Each transaction includes a copy of the original transaction.

SwiftyStoreKit uses the
SKPaymentTransactionObserver.paymentQueueRestoreCompletedTransactionsFinished method to detect when the transactions have been restored. The documentation for this method says:

This method is called after all restorable transactions have been processed by the payment queue. Your application is not required to do anything in this method.

While in theory this means that it should be possible to gather all the transactions' productIDs and return then, in practice it appears that SKPaymentTransactionObserver.paymentQueueRestoreCompletedTransactionsFinished is called once for each transaction.

If this is the actual behaviour of StoreKit, there doesn't seem to be a way of returning all restored productIDs in one callback. Worse, I'm not sure that there is a way to tell which is the last callback.

This is my interpretation though and I may have missed something. If anyone knows a way around this, please let me know.

@mortenholmgaard
Copy link
Author

I have taken a quick look at the code and to me it looks like you should be able to just use the
SKPaymentTransactionObserver.paymentQueueRestoreCompletedTransactionsFinished
Right now you don't really use it for any thing else than return .NothingToRestore

I think it could be done just iterating queue.transactions in SKPaymentTransactionObserver.paymentQueueRestoreCompletedTransactionsFinished
with the code from the .Restorecase in the method func paymentQueue(queue: SKPaymentQueue, updatedTransactions transactions: [SKPaymentTransaction]) and remove the .Restorecase from that method.

Does it make sense?

@bizz84
Copy link
Owner

bizz84 commented Apr 5, 2016

Haven't investigated yet but yes. I'll try to look into it this week.

@bizz84
Copy link
Owner

bizz84 commented Apr 8, 2016

Implemented tentative solution here:
https://github.com/bizz84/SwiftyStoreKit/pull/19/files
Feedback welcome

@mortenholmgaard
Copy link
Author

I have just tested it and it seems to work perfectly! - just as expected it restored multiple products in only one callback.
Hope you will make a pods release with this soon

@bizz84
Copy link
Owner

bizz84 commented Apr 10, 2016

This has now been merged and included in pod release 0.2.5

@bizz84 bizz84 closed this as completed Apr 10, 2016
@Vithanco Vithanco mentioned this issue Nov 3, 2018
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants