Question

I have an app that receives push notifications. In didReceiveRemoteNotifications, I would like to make the app show a particular view controller in the app's navigation controller (which happens to be the root view controller). What is the best way to make this happen? Can I get a reference to the navigation controller in the app delegate?

EDIT: Here is the code I'm trying to use right now. It appears to use the correct navigation controller, but it doesn't display the view controller at all, just a blank screen:

        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
        EventDetailViewController *destCon = [storyboard instantiateViewControllerWithIdentifier:@"EventDetailViewController"];
        destCon.event=notifyEvent;
        UINavigationController *navController =(UINavigationController *) self.window.rootViewController;
        [navController pushViewController:destCon animated:YES];

Here is what I'm seeing:

enter image description here

Was it helpful?

Solution

If your navigation controller is the root view controller of the window, then you can just use

(UINavigationController *)self.window.rootViewController

from the app delegate to access the one you created in the storyboard.

OTHER TIPS

I use something like below it works for me, try to modify for your usage

Stoaryboard is the name of your storyboard, when you recieve notification you can call your rootview LoginViewController

Make sure your viewcontroller in interface builder is set to yourControllerName in below example it is LoginView

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{

        //replace and push rootview manually
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
        LoginViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"LoginView"];
        UINavigationController *navigationController=[[UINavigationController alloc] initWithRootViewController:ivc];
        self.window.rootViewController =nil;
        self.window.rootViewController = navigationController;
        [self.window makeKeyAndVisible];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top