0

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.

Hiren Dhamecha
  • 626
  • 5
  • 15
Antonio
  • 1
  • 1

2 Answers2

0

I had a similar issue although my flow was a bit different. I ended up handling Push Notification event (when user taps on it) and storing the object at the app delegate level. In each view controller that appeared after that (in ViewDidLoad() method) I would check for that object and figure out whether to redirect the flow to the next view controller. To help with this, my notifications had a type associated with them. Unfortunately, I was not able to find a better solution.

P.S. It also appears like you're instantiating View Controllers in code and I was using Storyboards. However, the basic idea is the same. I ended

MK_Dev
  • 3,231
  • 5
  • 23
  • 44
0

@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 ...
    }
}
Community
  • 1
  • 1
Antonio
  • 1
  • 1