Fix "Nothing to Restore" even when transactions exist#640
Open
mshibanami wants to merge 2 commits intobizz84:developfrom
Open
Fix "Nothing to Restore" even when transactions exist#640mshibanami wants to merge 2 commits intobizz84:developfrom
mshibanami wants to merge 2 commits intobizz84:developfrom
Conversation
Owner
Generated by 🚫 Danger |
d374b93 to
ecaddfc
Compare
Author
Sorry I'm not sure how I should write tests in this case but I'm happy to write it if it makes sense. |
…ating transactions.
Author
|
I noticed that sometimes |
xhruso00
added a commit
to xhruso00/SwiftyStoreKit
that referenced
this pull request
Apr 3, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi,
I got the same problem with #620 on my macOS app.
This PR is for fixing that.
Problem details
StoreKit calls the following delegate methods of SwiftyStoreKit's
PaymentQueueControllerwhen restoring transactions is successful:paymentQueue(_:, updatedTransactions:)paymentQueueRestoreCompletedTransactionsFinished(_:)I confirmed that these methods are called simultaneously on their own different threads. So if there are so many restored transactions, the code in method 1 takes long time and then the delegate method 2 finishes earlier than 1. In other words, the completion of restoring transactions is finished earlier than the code that processes restored transactions.
It seems that SwiftyStoreKit's
PaymentQueueControllerdoesn't handle this case correctly andnilis set torestorePurchasesproperty ofRestorePurchasesControllerbefore finishing the restoration. I think this is the cause.I'm not sure how many transactions causes this problem. Maybe up to the machine power. This video is when 28 transactions exist:
Screen.Recording.2021-06-14.at.8.18.18.pm_converted.mov
Probably this happens on other platforms too.
Implementation
I newly defined
restorationDispatchQueueinPaymentQueueControllerso that the code of delegate methods 1 and 2 run on the same thread in order.This works fine on my Mac as follows:
Screen.Recording.2021-06-14.at.8.50.22.pm_converted.mov
By the way, maybe other delegate methods, such as
paymentQueue(_: updatedDownloads:), also need to be run on the same thread but since I'm neither familiar with StoreKit nor this library and I'm not too sure if it unnecessarily impacts other functionalities or not, I leave them as-is. (But please let me know if it actually doesn't impact or my approach is completely wrong.🙂)Thanks so much for maintaining this great library!