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 84a561b03e
commit 94ebbd025e
3 changed files with 27 additions and 1 deletions

View File

@@ -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)
}
}

View File

@@ -12,6 +12,7 @@
<string>applinks:develop.element.io</string>
<string>applinks:mobile.element.io</string>
<string>applinks:call.element.io</string>
<string>applinks:call.element.dev</string>
<string>webcredentials:*.element.io</string>
</array>
<key>com.apple.developer.usernotifications.communication</key>

1
changelog.d/1824.bugfix Normal file
View File

@@ -0,0 +1 @@
Redirect universal links directly to the browser if they're not supported