Skip to content

iOS multi-window project doesn't work (with fix) #2259

@abijr

Description

@abijr

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:

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:

  1. Have a working project with flutter_stripe
  2. Add and configure a multi-scene depency (e.g., car_play)
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions