From 1bf1f22087e0d58dab505b290b8bc026be81a63b Mon Sep 17 00:00:00 2001 From: Rafael Kellermann Streit Date: Wed, 20 Mar 2019 08:19:05 -0300 Subject: [PATCH] Try to open link as an universal URL instead of directly on the browser --- Rocket.Chat/Managers/WebBrowserManager.swift | 35 ++++++++++++-------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/Rocket.Chat/Managers/WebBrowserManager.swift b/Rocket.Chat/Managers/WebBrowserManager.swift index 15d0c1b0a1..f1b52c2c96 100644 --- a/Rocket.Chat/Managers/WebBrowserManager.swift +++ b/Rocket.Chat/Managers/WebBrowserManager.swift @@ -132,21 +132,30 @@ extension WebBrowserApp { } func open(url: URL) { - guard let url = appSchemeURL(forURL: url) else { return } - - switch self { - case .safari, .chrome, .opera, .firefox: - UIApplication.shared.open(url) - case .inAppSafari: - func present() { - let controller = SFSafariViewController(url: url) - UIWindow.topWindow.rootViewController?.present(controller, animated: true, completion: nil) + func openInBrowser() { + guard let browserURL = appSchemeURL(forURL: url) else { return } + + switch self { + case .safari, .chrome, .opera, .firefox: + UIApplication.shared.open(browserURL) + case .inAppSafari: + func present() { + let controller = SFSafariViewController(url: browserURL) + UIWindow.topWindow.rootViewController?.present(controller, animated: true, completion: nil) + } + + if Thread.isMainThread { + present() + } else { + DispatchQueue.main.async(execute: present) + } } + } - if Thread.isMainThread { - present() - } else { - DispatchQueue.main.async(execute: present) + let options = [UIApplication.OpenExternalURLOptionsKey.universalLinksOnly: true] + UIApplication.shared.open(url, options: options) { (success) in + if !success { + openInBrowser() } } }