Skip to content
This repository was archived by the owner on Jun 7, 2020. It is now read-only.

Commit b22da9f

Browse files
authored
Merge pull request #2590 from RocketChat/chore/prefer_universallinks_instead_webview_always
[NEW] Try to open links as an universal URL instead of directly on the browser
2 parents abe2c73 + 1bf1f22 commit b22da9f

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

Rocket.Chat/Managers/WebBrowserManager.swift

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,21 +132,30 @@ extension WebBrowserApp {
132132
}
133133

134134
func open(url: URL) {
135-
guard let url = appSchemeURL(forURL: url) else { return }
136-
137-
switch self {
138-
case .safari, .chrome, .opera, .firefox:
139-
UIApplication.shared.open(url)
140-
case .inAppSafari:
141-
func present() {
142-
let controller = SFSafariViewController(url: url)
143-
UIWindow.topWindow.rootViewController?.present(controller, animated: true, completion: nil)
135+
func openInBrowser() {
136+
guard let browserURL = appSchemeURL(forURL: url) else { return }
137+
138+
switch self {
139+
case .safari, .chrome, .opera, .firefox:
140+
UIApplication.shared.open(browserURL)
141+
case .inAppSafari:
142+
func present() {
143+
let controller = SFSafariViewController(url: browserURL)
144+
UIWindow.topWindow.rootViewController?.present(controller, animated: true, completion: nil)
145+
}
146+
147+
if Thread.isMainThread {
148+
present()
149+
} else {
150+
DispatchQueue.main.async(execute: present)
151+
}
144152
}
153+
}
145154

146-
if Thread.isMainThread {
147-
present()
148-
} else {
149-
DispatchQueue.main.async(execute: present)
155+
let options = [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true]
156+
UIApplication.shared.open(url, options: options) { (success) in
157+
if !success {
158+
openInBrowser()
150159
}
151160
}
152161
}

0 commit comments

Comments
 (0)