I'm trying to handle push notification click. When push notification comes in, I want to direct the user to a certain part of the application after clicking on push notification. Firstly, there is SplashScreen in the application, where it shows a TabBar as "Present Modally" by checking whether the user has previously logged in from API Call. What I want to show the user is the content of a feed in the table view in the navigation controller in the first tab of the TabBar. But I can't reach it and show it as clicked on tableview.
-SplashScreen -------> TabBar -> Navigation Controller -> Table View Controller -> ContentView(I want to show)
I tried writing the UIApplication extension but it didn't work. Here's the extension
extension UIApplication {
class func topViewController(base: UIViewController? = (UIApplication.shared.delegate as! AppDelegate).window?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return topViewController(base: nav.visibleViewController)
}
if let tab = base as? UITabBarController {
if let selected = tab.selectedViewController {
return topViewController(base: selected)
}
}
if let presented = base?.presentedViewController {
return topViewController(base: presented)
}
return base
}
}
I wrote the following code in didFinishLaunchingWithOptions
if let option = launchOptions {
let info = option[UIApplication.LaunchOptionsKey.remoteNotification] as? [String:Any]
if let info = info {
if info["type"] as! String == "site-notification" {
let contentVC = Destination().FeedCoontentVC
contentVC.selectedSite = (info["link"] as! String)
contentVC.title = "asd"
UIApplication.topViewController()?.present(contentVC, animated: true, completion: nil)
}
}
}