diff --git a/CHANGELOG.md b/CHANGELOG.md index d00b2257c0..0b304bd39a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## x.x.x - 2025-x-x + +**Fixes** +- [#2201](https://github.com/stripe/stripe-react-native/issues/2201) Fixed iOS sheets (PaymentSheet, CustomerSheet, AddressSheet, etc.) not presenting in scene-based lifecycle apps. The SDK now properly supports both traditional app delegates and scene-based lifecycles (iOS 13+) by using `RCTKeyWindow`. + ## 0.56.0 - 2025-11-06 **Changes** diff --git a/ios/AddressSheet/AddressSheetView.swift b/ios/AddressSheet/AddressSheetView.swift index 0cb3d2b306..f0f79f227b 100644 --- a/ios/AddressSheet/AddressSheetView.swift +++ b/ios/AddressSheet/AddressSheetView.swift @@ -76,7 +76,7 @@ public class AddressSheetView: UIView { let navigationController = UINavigationController(rootViewController: addressViewController!) navigationController.modalPresentationStyle = getModalPresentationStyle() navigationController.modalTransitionStyle = getModalTransitionStyle() - let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) + let vc = findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()) vc.present(navigationController, animated: true) } diff --git a/ios/FinancialConnections.swift b/ios/FinancialConnections.swift index 5505e7566b..12ec726895 100644 --- a/ios/FinancialConnections.swift +++ b/ios/FinancialConnections.swift @@ -26,7 +26,7 @@ class FinancialConnections { ) financialConnectionsSheet.onEvent = onEvent financialConnectionsSheet.present( - from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()), + from: findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()), completion: { result in switch result { case .completed(session: let session): @@ -55,7 +55,7 @@ class FinancialConnections { ) financialConnectionsSheet.onEvent = onEvent financialConnectionsSheet.presentForToken( - from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()), + from: findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()), completion: { result in switch result { case .completed(result: let result): diff --git a/ios/PushProvisioning/AddToWalletButtonView.swift b/ios/PushProvisioning/AddToWalletButtonView.swift index a581f89e5c..4743edb0fd 100644 --- a/ios/PushProvisioning/AddToWalletButtonView.swift +++ b/ios/PushProvisioning/AddToWalletButtonView.swift @@ -89,7 +89,7 @@ public class AddToWalletButtonView: UIView { return self.testEnv ? STPFakeAddPaymentPassViewController(requestConfiguration: config, delegate: self) : PKAddPaymentPassViewController(requestConfiguration: config, delegate: self) }() - let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) + let vc = findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()) vc.present(controller!, animated: true, completion: nil) } diff --git a/ios/StripeSdkImpl+CustomerSheet.swift b/ios/StripeSdkImpl+CustomerSheet.swift index 66335dfa7f..47ebd51f6e 100644 --- a/ios/StripeSdkImpl+CustomerSheet.swift +++ b/ios/StripeSdkImpl+CustomerSheet.swift @@ -107,7 +107,7 @@ extension StripeSdkImpl { } DispatchQueue.main.async { - self.customerSheetViewController = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) + self.customerSheetViewController = findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()) if let customerSheetViewController = self.customerSheetViewController { customerSheetViewController.modalPresentationStyle = CustomerSheetUtils.getModalPresentationStyle(params["presentationStyle"] as? String) customerSheetViewController.modalTransitionStyle = CustomerSheetUtils.getModalTransitionStyle(params["animationStyle"] as? String) diff --git a/ios/StripeSdkImpl.swift b/ios/StripeSdkImpl.swift index 24f95798dd..11c0201089 100644 --- a/ios/StripeSdkImpl.swift +++ b/ios/StripeSdkImpl.swift @@ -189,7 +189,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate { rejecter reject: @escaping RCTPromiseRejectBlock) -> Void { DispatchQueue.main.async { if (self.paymentSheetFlowController != nil) { - self.paymentSheetFlowController?.confirm(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) { paymentResult in + self.paymentSheetFlowController?.confirm(from: RCTKeyWindow()?.rootViewController ?? UIViewController()) { paymentResult in switch paymentResult { case .completed: resolve([]) @@ -228,7 +228,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate { } } DispatchQueue.main.async { - paymentSheetViewController = UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController() + paymentSheetViewController = RCTKeyWindow()?.rootViewController ?? UIViewController() if let paymentSheetFlowController = self.paymentSheetFlowController { paymentSheetFlowController.presentPaymentOptions(from: findViewControllerPresenter(from: paymentSheetViewController!) ) { didCancel in @@ -451,7 +451,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate { if let applePaymentAuthorizationController = self.applePaymentAuthorizationController { applePaymentAuthorizationController.delegate = self DispatchQueue.main.async { - let vc = findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) + let vc = findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()) vc.present( applePaymentAuthorizationController, animated: true, @@ -784,7 +784,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate { clientSecret: clientSecret as String, returnURL: connectionsReturnURL, params: collectParams, - from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()), + from: findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()), onEvent: onEvent ) { intent, error in if let error = error { @@ -811,7 +811,7 @@ public class StripeSdkImpl: NSObject, UIAdaptivePresentationControllerDelegate { clientSecret: clientSecret as String, returnURL: connectionsReturnURL, params: collectParams, - from: findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()), + from: findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()), onEvent: onEvent ) { intent, error in if let error = error { @@ -1242,7 +1242,7 @@ func findViewControllerPresenter(from uiViewController: UIViewController) -> UIV extension StripeSdkImpl: STPAuthenticationContext { public func authenticationPresentingViewController() -> UIViewController { - return findViewControllerPresenter(from: UIApplication.shared.delegate?.window??.rootViewController ?? UIViewController()) + return findViewControllerPresenter(from: RCTKeyWindow()?.rootViewController ?? UIViewController()) } }