0

I have an app which currently uses push notifications and we have started trying to open specific pages of the app from JSON pushes.

This is the code for one of possible pages to open:

//Extract the notification data
    if let notificationPayload = launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {
        // Get which page to open
        let viewload = notificationPayload["view"] as? NSString
        let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
        //Load correct view
                    if viewload == "videos" {
            let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
            let initialViewController : UIViewController = mainStoryboard.instantiateViewControllerWithIdentifier("Videos") as! UIViewController
            self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
            self.window?.rootViewController = initialViewController
            self.window?.makeKeyAndVisible()
        }
    }

The problem is that doing this skips the viewcontroller that allows the burger menu to be opened at the side.

Is there a way to open the burger menu controller and load the correct view from the push?

If you need more information let me know, I'll post updates as needed

Lister
  • 1,098
  • 1
  • 9
  • 19
  • Why are you creating a new window? – Wain Jun 29 '15 at 10:37
  • I cant find the question any more but it was suggested in an answer for a similar issue. From what I understood it was manipulating a window, not creating, but I see I may have been wrong on that one re-reading it. – Lister Jun 29 '15 at 10:42
  • I have found the previous question, it was one of mine! Shows you my great memory: http://stackoverflow.com/questions/30592521/opening-view-controller-from-app-delegate-using-swift – Lister Jun 30 '15 at 08:28

1 Answers1

0

You generally shouldn't be creating a new window and setting the root view controller. At least not if you don't make the root view controller the true root VC for your app and ask it to display your specific content from the push.

Generally your root VC should understand that there may be a need to show a particular VC (from a push or somewhere else) and offer the app delegate a way to do that. That may be achieved by forwarding the request until some VC can handle it, it may be simply pushing it onto a navigation controller, it may be posting a notification, or it may be presenting a modal.

There are many potential options, you need to decide which is correct for your app, but the important part is that it ties in with your existing view hierarchy rather than replacing it.

Wain
  • 118,658
  • 15
  • 128
  • 151
  • The first thing that popped to mine would be I could create a variable at open which stores what page to load, and segue through the appropriate view controllers until I hit where I want to load? And if this is an option would the load time be increased/flashes of pages be visible? – Lister Jun 30 '15 at 08:31