Fixes #1824 - Redirect universal links directly to the browser if they're not supported

This commit is contained in:
Stefan Ceriu
2023-10-05 09:30:11 +03:00
parent 3ff983a48b
commit cd48fc10d4
3 changed files with 27 additions and 1 deletions
+25 -1
View File
@@ -45,7 +45,7 @@ struct Application: App {
}) })
.onOpenURL { .onOpenURL {
if !appCoordinator.handleDeepLink($0) { if !appCoordinator.handleDeepLink($0) {
openURL($0) openURLInSystemBrowser($0)
} }
} }
.introspect(.window, on: .supportedVersions) { window in .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 { private var shouldHideStatusBar: Bool {
ProcessInfo.isRunningUITests 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)
}
} }
@@ -12,6 +12,7 @@
<string>applinks:develop.element.io</string> <string>applinks:develop.element.io</string>
<string>applinks:mobile.element.io</string> <string>applinks:mobile.element.io</string>
<string>applinks:call.element.io</string> <string>applinks:call.element.io</string>
<string>applinks:call.element.dev</string>
<string>webcredentials:*.element.io</string> <string>webcredentials:*.element.io</string>
</array> </array>
<key>com.apple.developer.usernotifications.communication</key> <key>com.apple.developer.usernotifications.communication</key>
+1
View File
@@ -0,0 +1 @@
Redirect universal links directly to the browser if they're not supported