From 078f9e076d1ef08800d9a4a6597f474363bba949 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 15 Sep 2019 16:13:18 -0400 Subject: [PATCH] Allow searching for posts/users by opening URL with the tusker:// protocol --- Tusker/AppDelegate.swift | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/Tusker/AppDelegate.swift b/Tusker/AppDelegate.swift index df476a2a..f243587b 100644 --- a/Tusker/AppDelegate.swift +++ b/Tusker/AppDelegate.swift @@ -30,6 +30,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool { if url.host == "x-callback-url" { return XCBManager.handle(url: url) + } else if var components = URLComponents(url: url, resolvingAgainstBaseURL: false), + let tabBarController = window!.rootViewController as? MainTabBarViewController, + let navigationController = tabBarController.viewControllers?[3] as? UINavigationController, + let searchController = navigationController.viewControllers.first as? SearchTableViewController { + + components.scheme = "https" + + tabBarController.selectedIndex = 3 + navigationController.popToRootViewController(animated: false) + + searchController.loadViewIfNeeded() + + let query = components.url!.absoluteString + searchController.searchController.searchBar.searchTextField.text = query + searchController.performSearch(query: query) + + return true } return false }