I have a navigationVIewController as a rootViewController at one case and a viewController as a rootViewController in one case.
When the rootViewController is the viewController, i'm unable to show the viewController at that tabbar using the below code, in the didRecieveRemoteNotification method.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
if let type = userInfo["type"] as! String! {
if UIApplication.shared.applicationState == .inactive {
if self.window?.rootViewController as? UINavigationController != nil {
//Works Fine
} else {
let storyBoard = UIStoryboard(name: "Main", bundle: nil)
let myNavigationController = storyBoard.instantiateViewController(withIdentifier: "navBarID") as! UINavigationController
let myTabbarController = myNavigationController.viewControllers[0] as! UITabBarController
if type == "newsfeed" {
myTabbarController.selectedViewController = myTabbarController.viewControllers![3]
} else if type == "event" {
myTabbarController.selectedViewController = myTabbarController.viewControllers![2]
}
}
} else {
// Foreground
}
}
}