diff --git a/podcasts/AppDelegate+UrlHandling.swift b/podcasts/AppDelegate+UrlHandling.swift index 68a3bbe54d..e1983410ad 100644 --- a/podcasts/AppDelegate+UrlHandling.swift +++ b/podcasts/AppDelegate+UrlHandling.swift @@ -169,7 +169,13 @@ extension AppDelegate { // Support for subscribing to a feed URL JLRoutes.global().addRoute("/subscribe/*") { [weak self] parameters -> Bool in - guard let strongSelf = self, let controller = SceneHelper.rootViewController(), let subscribeUrl = (parameters[JLRouteURLKey] as? URL)?.absoluteString else { return false } + guard + let strongSelf = self, + let rootController = SceneHelper.rootViewController(includeTopMost: false), //I don't want to consider the top most presented but the main root instead + let subscribeUrl = (parameters[JLRouteURLKey] as? URL)?.absoluteString + else { + return false + } let prefix = "pktc://subscribe/" if prefix.count >= subscribeUrl.count { return true } // this request is missing a URL @@ -179,8 +185,8 @@ extension AppDelegate { let searchTerm = !feedUrl.hasPrefix("http://") && !feedUrl.hasPrefix("https://") ? "http://\(feedUrl)" : feedUrl strongSelf.progressDialog = ShiftyLoadingAlert(title: L10n.podcastLoading) - controller.dismiss(animated: false, completion: nil) - strongSelf.progressDialog?.showAlert(controller, hasProgress: false, completion: { + rootController.dismiss(animated: false, completion: nil) + strongSelf.progressDialog?.showAlert(rootController, hasProgress: false, completion: { MainServerHandler.shared.podcastSearch(searchTerm: searchTerm) { response in guard let uuid = response?.result?.podcast?.uuid else { DispatchQueue.main.async { diff --git a/podcasts/SceneHelper.swift b/podcasts/SceneHelper.swift index 50a1f867cc..361a574538 100644 --- a/podcasts/SceneHelper.swift +++ b/podcasts/SceneHelper.swift @@ -23,10 +23,13 @@ class SceneHelper { return UIWindow(frame: UIScreen.main.bounds) } - class func rootViewController() -> UIViewController? { + class func rootViewController(includeTopMost: Bool = true) -> UIViewController? { let appScene = connectedScene()?.windows.first(where: { $0.rootViewController is MainTabBarController }) let rootVC = appScene?.rootViewController - return rootVC?.topMostPresentedViewController ?? rootVC + if includeTopMost { + return rootVC?.topMostPresentedViewController ?? rootVC + } + return rootVC } /// Returns the main window for the app from the AppDelegate