From 3616e6bada1420de00fa2e2c38616590b7da4239 Mon Sep 17 00:00:00 2001 From: Jack Newcombe Date: Fri, 19 Apr 2024 20:20:29 +0100 Subject: [PATCH] Ensure web redirect presentation gracefully handles testing cases where no window is present --- ...edirectPaymentMethodTokenizationViewModel.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/WebRedirectPaymentMethodTokenizationViewModel.swift b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/WebRedirectPaymentMethodTokenizationViewModel.swift index 609257d7d3..121bac50b4 100644 --- a/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/WebRedirectPaymentMethodTokenizationViewModel.swift +++ b/Sources/PrimerSDK/Classes/User Interface/TokenizationViewModels/WebRedirectPaymentMethodTokenizationViewModel.swift @@ -198,7 +198,15 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi responseCode: nil ) + Analytics.Service.record(events: [presentEvent, networkEvent]) + + guard UIApplication.shared.windows.count > 0 else { + self.handleWebViewControllerPresentedCompletion() + seal.fulfill() + return + } + if PrimerUIManager.primerRootViewController == nil { firstly { PrimerUIManager.prepareRootViewController() @@ -206,7 +214,7 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi .done { PrimerUIManager.primerRootViewController?.present(self.webViewController!, animated: true, completion: { DispatchQueue.main.async { - self.handleWebViewControlllerPresentedCompletion() + self.handleWebViewControllerPresentedCompletion() seal.fulfill() } }) @@ -215,7 +223,7 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi } else { PrimerUIManager.primerRootViewController?.present(self.webViewController!, animated: true, completion: { DispatchQueue.main.async { - self.handleWebViewControlllerPresentedCompletion() + self.handleWebViewControllerPresentedCompletion() seal.fulfill() } }) @@ -224,7 +232,7 @@ class WebRedirectPaymentMethodTokenizationViewModel: PaymentMethodTokenizationVi } } - private func handleWebViewControlllerPresentedCompletion() { + private func handleWebViewControllerPresentedCompletion() { DispatchQueue.main.async { let viewEvent = Analytics.Event.ui( action: .view,