From 2bc624feeae110931934a34d1624a6ab8bc5fa2e Mon Sep 17 00:00:00 2001 From: Stefan Ceriu Date: Thu, 5 Oct 2023 09:30:11 +0300 Subject: [PATCH] Fixes #1824 - Redirect universal links directly to the browser if they're not supported --- .../Sources/Application/Application.swift | 26 ++++++++++++++++++- .../SupportingFiles/ElementX.entitlements | 1 + changelog.d/1824.bugfix | 1 + 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 changelog.d/1824.bugfix diff --git a/ElementX/Sources/Application/Application.swift b/ElementX/Sources/Application/Application.swift index cc6c52ba79..69a576ec99 100644 --- a/ElementX/Sources/Application/Application.swift +++ b/ElementX/Sources/Application/Application.swift @@ -45,7 +45,7 @@ struct Application: App { }) .onOpenURL { if !appCoordinator.handleDeepLink($0) { - openURL($0) + openURLInSystemBrowser($0) } } .introspect(.window, on: .supportedVersions) { window in @@ -57,8 +57,32 @@ struct Application: App { } } } + + // MARK: - Private + /// Hide the status bar so it doesn't interfere with the screenshot tests private var shouldHideStatusBar: Bool { ProcessInfo.isRunningUITests } + + /// https://github.com/vector-im/element-x-ios/issues/1824 + /// Avoid opening universal links in other app variants and infinite loops between them + private func openURLInSystemBrowser(_ originalURL: URL) { + guard var urlComponents = URLComponents(url: originalURL, resolvingAgainstBaseURL: true) else { + openURL(originalURL) + return + } + + var queryItems = urlComponents.queryItems ?? [] + queryItems.append(.init(name: "no_universal_links", value: "true")) + + urlComponents.queryItems = queryItems + + guard let url = urlComponents.url else { + openURL(originalURL) + return + } + + openURL(url) + } } diff --git a/ElementX/SupportingFiles/ElementX.entitlements b/ElementX/SupportingFiles/ElementX.entitlements index 892e31c515..9c14dc28b8 100644 --- a/ElementX/SupportingFiles/ElementX.entitlements +++ b/ElementX/SupportingFiles/ElementX.entitlements @@ -12,6 +12,7 @@ applinks:develop.element.io applinks:mobile.element.io applinks:call.element.io + applinks:call.element.dev webcredentials:*.element.io com.apple.developer.usernotifications.communication diff --git a/changelog.d/1824.bugfix b/changelog.d/1824.bugfix new file mode 100644 index 0000000000..d57c2004d6 --- /dev/null +++ b/changelog.d/1824.bugfix @@ -0,0 +1 @@ +Redirect universal links directly to the browser if they're not supported \ No newline at end of file