From 3f4c4eb6c58d3f4fcc4ed26854ae4a27239387ee Mon Sep 17 00:00:00 2001 From: Cesar de la Vega Date: Wed, 4 Dec 2024 18:20:55 +0100 Subject: [PATCH] Customer Center deeplinks should always be opened externally (#4533) * check if it's a deeplink * match http or https * add log --- RevenueCatUI/CustomerCenter/URLUtilities.swift | 13 +++++++++++++ .../ViewModels/ManageSubscriptionsViewModel.swift | 6 +++++- RevenueCatUI/Data/Strings.swift | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/RevenueCatUI/CustomerCenter/URLUtilities.swift b/RevenueCatUI/CustomerCenter/URLUtilities.swift index b0f4ec1ad7..32f809475f 100644 --- a/RevenueCatUI/CustomerCenter/URLUtilities.swift +++ b/RevenueCatUI/CustomerCenter/URLUtilities.swift @@ -74,6 +74,19 @@ enum URLUtilities { } +extension URL { + + var isDeeplink: Bool { + switch scheme?.lowercased() { + case "http", "https": + return false + default: + return true + } + } + +} + private extension URLUtilities { static var isAppExtension: Bool { diff --git a/RevenueCatUI/CustomerCenter/ViewModels/ManageSubscriptionsViewModel.swift b/RevenueCatUI/CustomerCenter/ViewModels/ManageSubscriptionsViewModel.swift index be3fc1c7bf..55f6843ac1 100644 --- a/RevenueCatUI/CustomerCenter/ViewModels/ManageSubscriptionsViewModel.swift +++ b/RevenueCatUI/CustomerCenter/ViewModels/ManageSubscriptionsViewModel.swift @@ -226,10 +226,14 @@ private extension ManageSubscriptionsViewModel { return } switch openMethod { - case .external: + case .external, + _ where url.isDeeplink: URLUtilities.openURLIfNotAppExtension(url) case .inApp: self.inAppBrowserURL = .init(url: url) + @unknown default: + Logger.warning(Strings.could_not_determine_type_of_custom_url) + URLUtilities.openURLIfNotAppExtension(url) } default: break diff --git a/RevenueCatUI/Data/Strings.swift b/RevenueCatUI/Data/Strings.swift index 728de5743c..0facdade6d 100644 --- a/RevenueCatUI/Data/Strings.swift +++ b/RevenueCatUI/Data/Strings.swift @@ -67,6 +67,7 @@ enum Strings { case could_not_offer_for_active_subscriptions(String, String) case error_fetching_promotional_offer(Error) case promo_offer_not_loaded + case could_not_determine_type_of_custom_url } @@ -207,6 +208,9 @@ extension Strings: CustomStringConvertible { case .could_not_offer_for_active_subscriptions(let discount, let subscription): return "Could not find offer with id \(discount) for active subscription \(subscription)" + case .could_not_determine_type_of_custom_url: + return "Could not determine the type of custom URL, the URL will be opened externally." + } }