Antonio Antonio - 6 months ago 23
Swift Question

Push Notification open specific screen in TabBarController NavigationController revealViewController

Here is what I am trying to do.
When I receive the push notification and I tap I want to show a specific screen in my app. I found a lot about it but I am having trouble due to the complexity of the structure of my application.
Here is how the app is structured:



I want to pass some arguments to the
DetailViewContorller
so I can make sure I get the right results when opening the screen.
Here is the screenshot of my app structure
application Folow

With the following code in my AppDelegate:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tb = storyboard.instantiateViewControllerWithIdentifier("TabBarVC") as! UITabBarController
tb.selectedIndex = 1
window?.rootViewController? = tb


I have managed to get to the tabbar when tapping on the notification but I am not happy with the results. I am still having the following issues:


  1. the
    revealViewController
    is nil so I am not able to open my setting panel

  2. I still don't get to the
    DetailViewController
    which is at the bottom of my view hierarchy



Any hint will be appreciated.

Answer

@MK_Dev, Thanks for your suggestion but I was looking for something easier to manage.

This has actually helped me. Get top most UIViewController

Here is what I did:

if var topControl = UIApplication.sharedApplication().keyWindow?.rootViewController {
            while let presentedContreller = topControl.presentedViewController{
                topControl = presentedContreller
            }
            if topControl.childViewControllers[0].isKindOfClass(MyCustomClassVC) {
            // Check if the user is already on the VC we are trying to open
                let chatController = topControl.childViewControllers[0] as! MyCustomClassVC 
// ... any additional code you need to add here ...
    }
}