Skip to content

Fix iOS 26.4+ restore: defer handleRestore to allow pending transactions to arrive#286

Merged
keesvandieren merged 4 commits into
masterfrom
copilot/fix-ios-restore-transaction-issue
Apr 13, 2026
Merged

Fix iOS 26.4+ restore: defer handleRestore to allow pending transactions to arrive#286
keesvandieren merged 4 commits into
masterfrom
copilot/fix-ios-restore-transaction-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

On iOS 26.4+, restoreCompletedTransactionsFinished fires before updatedTransactions delivers the restored transactions (~60ms gap observed), causing handleRestore to always receive an empty array. Only affects StoreKit 1 (PurchaseManageriOSApple); StoreKit 2 uses sequential async iteration and is unaffected.

Changes

  • Deferred delivery: Replace immediate handleRestore call in restoreCompletedTransactionsFinished with a 500ms libGDX Timer.schedule(), allowing pending updatedTransactions callbacks to populate restoredTransactions first
  • Timer lifecycle: Cancel timer in dispose(), purchaseRestore(), and restoreCompletedTransactionsFailed() to prevent leaks and stale deliveries
// Before: delivers empty array on iOS 26.4+
observer.handleRestore(restoredTransactions.toArray(...));

// After: defers delivery to allow pending restored transactions to arrive
cancelRestoreTimer();
restoreTimerTask = Timer.schedule(new Timer.Task() {
    @Override
    public void run() {
        restoreTimerTask = null;
        observer.handleRestore(restoredTransactions.toArray(...));
        restoredTransactions.clear();
    }
}, 0.5f);

Note: Build cannot be verified in CI due to sandbox network restrictions (Android Gradle Plugin resolution fails). The change is limited to a single file.

Copilot AI and others added 2 commits April 13, 2026 19:29
… arrive

On iOS 26.4+, restoreCompletedTransactionsFinished may be called before
all restored transactions are delivered via updatedTransactions. This
caused handleRestore to be called with an empty array.

Fix by deferring the handleRestore delivery using a 500ms timer, giving
pending updatedTransactions callbacks time to process restored
transactions first.

Agent-Logs-Url: https://github.com/libgdx/gdx-pay/sessions/9dc875b1-3666-46a7-a485-0946d118e71b

Co-authored-by: keesvandieren <863966+keesvandieren@users.noreply.github.com>
Agent-Logs-Url: https://github.com/libgdx/gdx-pay/sessions/9dc875b1-3666-46a7-a485-0946d118e71b

Co-authored-by: keesvandieren <863966+keesvandieren@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix iOS restorePurchases to handle transactions correctly Fix iOS 26.4+ restore: defer handleRestore to allow pending transactions to arrive Apr 13, 2026
Copilot AI requested a review from keesvandieren April 13, 2026 19:33
@keesvandieren
Copy link
Copy Markdown
Member

@copilot why did you prefer the iOS specifc timer over Mobivms standard Java timer as specified in #285 (comment)?

(I don't care too much about which one, except that the one in #285 (comment) looks a bit cleaner)

Replaces the iOS-specific NSTimer (which didn't compile) with
com.badlogic.gdx.utils.Timer, matching the approach suggested
in issue #285.

Agent-Logs-Url: https://github.com/libgdx/gdx-pay/sessions/042d60fa-727f-43f6-bef1-8e8002016b3b

Co-authored-by: keesvandieren <863966+keesvandieren@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 13, 2026

@copilot why did you prefer the iOS specifc timer over Mobivms standard Java timer as specified in #285 (comment)?

(I don't care too much abou...

Switched to libGDX's Timer.schedule() in a44088a. This also fixes the compilation issue — NSTimer.createScheduled wasn't available in the RoboVM bindings used here.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -Xms1024m -Xmx2048m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp (dns block)
  • google-web-toolkit.googlecode.com
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-820a08ca2d3eb870/dbs/java/working/files-to-index3552600539885869028.list --sourceArchiveDir=/tmp/codeql-scratch-820a08ca2d3eb870/dbs/java/src --outputDir=/tmp/codeql-scratch-820a08ca2d3eb870/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@keesvandieren keesvandieren marked this pull request as ready for review April 13, 2026 19:55
@keesvandieren keesvandieren merged commit cf26e31 into master Apr 13, 2026
1 check passed
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

Successfully merging this pull request may close these issues.

iOS calls handleRestore before restore is finished.

2 participants