Repository navigation
Commit d2b9d20
authored
[in_app_purchase_storekit] Use purchase(confirmIn:) for StoreKit 2 purchases (flutter#13410)
Fixes flutter#194373 Fixes flutter#195494
This PR switches StoreKit 2 purchases from the scene-less Product.purchase(options:) to Product.purchase(confirmIn:options:) whenever the plugin has a view controller attached to a window scene (iOS 17+) or an NSWindow (macOS 15.2+).
`purchase(confirmIn:)` is Apple's recommended purchase API for UIKit/AppKit apps. The
scene-less variant relies on StoreKit locating a UI anchor itself; on iOS 27 / iPadOS 27
that lookup fails (`Could not find a UI anchor for … purchase`) and the `await` never
returns. In the field this surfaced as App Review rejecting iPad subscription purchases
(flutter#194373); on the iOS 27 simulator it surfaced as every StoreKit 2 purchase test timing
out (flutter#195494). The scene-less call remains the fallback for iOS < 17 / macOS < 15.2 and
for headless engines whose registrar has no view in a window.
**Test changes**
The test `setUp` now hands the plugin a registrar stub backed by the test host's root
view controller, mirroring how the plugin runs inside a real Flutter app, so the
existing purchase tests exercise the `confirmIn:` path.
Two further adjustments were needed for the iOS 27 ipad simulator:
- `testGetTransactionJsonRepresentation` makes a purchase and then asks the plugin to look
that transaction up by its ID. It took the ID from the test framework's
`SKTestTransaction.originalTransactionIdentifier`, which only worked because, on earlier
OS versions, that value happened to equal the StoreKit 2 `Transaction.id` the plugin
matches on (both are 0 for the first purchase). On iOS 27 StoreKitTest numbers
transactions differently (`identifier` is a non-zero counter, `originalTransactionIdentifier`
is reported as 0), so the lookup found nothing. The test now uses `identifier`, which is the
field that corresponds to `Transaction.id` on every OS version.
- `testFailedProductUnavilablePurchase` and `testPurchaseWithIntroductoryOfferEligibilityJWS`
are skipped on iOS 27+. Both make a purchase that fails by design, and on iOS 27
StoreKitTest shows an error dialog for failed purchases even with `disableDialogs`
([iOS 27 release notes, known issue 184255116](https://developer.apple.com/documentation/ios-ipados-release-notes/ios-ipados-27-release-notes)), so the purchase never completes. Since StoreKit serializes purchases per process, each of those also blocked every later purchase test, which is the cascade you see in the CI log.
## Pre-Review Checklist1 parent 2c2b1e7 commit d2b9d20
4 files changed
Lines changed: 61 additions & 3 deletions
File tree
- packages/in_app_purchase/in_app_purchase_storekit
- darwin/in_app_purchase_storekit/Sources/in_app_purchase_storekit/StoreKit2
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
1 | 6 | | |
2 | 7 | | |
3 | 8 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
108 | 108 | | |
109 | 109 | | |
110 | 110 | | |
111 | | - | |
| 111 | + | |
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
591 | 620 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
53 | 64 | | |
54 | 65 | | |
55 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
56 | 78 | | |
57 | 79 | | |
58 | 80 | | |
| |||
238 | 260 | | |
239 | 261 | | |
240 | 262 | | |
241 | | - | |
| 263 | + | |
242 | 264 | | |
243 | 265 | | |
244 | 266 | | |
| |||
268 | 290 | | |
269 | 291 | | |
270 | 292 | | |
| 293 | + | |
271 | 294 | | |
272 | 295 | | |
273 | 296 | | |
| |||
415 | 438 | | |
416 | 439 | | |
417 | 440 | | |
| 441 | + | |
418 | 442 | | |
419 | 443 | | |
420 | 444 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| |||
0 commit comments