-
-
Notifications
You must be signed in to change notification settings - Fork 633
Description
Describe the bug
When using a scene delegate or multiple windows (not entirely sure about the internals) in iOS, PaymentSheet fails to load.
Related tickets/bugs:
- presentPaymentSheet() not working in scene-based life-cycle apps stripe/stripe-react-native#2201
- Not open PaymentSheet #2158
Tentative Fix
I'd open a PR, but not confident on my swift/iOS skills.
https://stackoverflow.com/questions/57134259/how-to-resolve-keywindow-was-deprecated-in-ios-13-0
Replaced
paymentSheetViewController = UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()With
let keyWindow = UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.compactMap({$0 as? UIWindowScene})
.first?.windows
.filter({$0.isKeyWindow}).first
paymentSheetViewController = keyWindow?.rootViewController ?? UIViewController()There are a few instances of the UIApplication.shared.delegate?.window? in the packages/stripe_ios directory, I cloned the repo, set up a pubspec_override.yaml and replaced all of those, with good results (at least in the emulator).
To Reproduce
Steps to reproduce the behavior:
- Have a working project with flutter_stripe
- Add and configure a multi-scene depency (e.g., car_play)
- PaymentSheet stops working.
Expected behavior
PaymentSheet should continue to work.
Smartphone / tablet
- Device: iPhone (15, 16)
- OS: iOS 13+
- Package version: 12.0.2, 12.10
- Flutter version: Flutter 3.35.3
Additional context
I suspect other flutter_stripe features to fail with similar setups but can't confirm.