Launching a specific viewController in response to a remote push notification

I'm creating an app who's storyboard flows like the image below:

When a user logs in from "Sysalert View Controller" they are brought into "Message List View Controller" where I do an NSURLConnection to load some JSON into the table. When a user taps a row in the table, they are brought into "Message Details" which shows more detailed information for that message.

When a user launches the app from a push notification, regardless of the state of the app prior to launching, I want the app to load the "Message List" data from my server and then show them the message that's just been pushed to the device.

I know I need to use didFinishLaunchingWithOptions to tell the app to react to the push notification but how do I setup the view hierarchy so that the "Message List" view controller loads its data and then pushes the "Message Details" view controller onto the stack for the appropriate message?

Essentially this kind of mimics the behaviour of the Messages or Mail apps. Where opening with a notification brings you to a view controller for that message but you are still able to move back in the hierarchy as if you had launched the app from the initial viewController and traversed through the viewControllers in turn.


It's possible to do what you describe, but I would not recommend it.

Frist, place a disconnected view controller with the view that you want in the storyboard, give the view controller an identifier, something like "My Push Notification View"

In didFinishLaunchingWithOptions:, You can get to the rootViewController from the app delegate. This controller will be the navigation controller. Using navigation controller, you can push a new view controller on top of the stack. To create the new view controller, you instantiate the view controller with the identifier "My Push Notification View".

UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
UIViewController *notificationController = [navController.storyboard instantiateViewControllerWithIdentifier:@"My Push Notification View"];

[navController pushViewController:notificationController animated:YES];

I think you will want to use something like -presentViewController:animated:completion: to show a modal view instead of interrupting the navigation stack.

UIViewController *rootController = (UIViewController *)self.window.rootViewController;
UIViewController *notificationController = [rootController.storyboard instantiateViewControllerWithIdentifier:@"My Push Notification View"];

[rootController presentViewController:notificationController animated:YES completion:NULL];

Try This i used in one of my application, User a variable in app delegate as a global

 ex: BOOL gotNotifcation;

-(void)application:(UIApplication*)app didReceiveRemoteNotification:(NSDictionary *)userInfo
    NotificationsViewController *notificationobject = [[NotificationsViewController alloc]init];
    [self.navigationController pushViewController:notificationobject animated:YES];
    gotNotifcation = YES;   

In NotificationsViewController for back button action if it is customized button

    AppDelegate *delegate =(AppDelegate *)[UIApplication sharedApplication].delegate;

        delegate.gotNotifcation = NO;
        MessageListController *feed = [[MessageListController alloc] init];
        [self.navigationController pushViewController:feed animated:NO];
        [self.navigationController popViewControllerAnimated:NO];

Need Your Help

vba error handling in loop

vba error-handling

New to vba, trying an 'on error goto' but, I keep getting errors 'index out of range'.

iOS 11 beta 4 presentRenderbuffer crash

ios xcode opengl-es gpuimage ios11

My app crashes on iOS 11 beta 4 (15A5327g) when [EAGLContext presentRenderbuffer:] method is called. It happens only when I debugging in Xcode. When I launch app manually it doesn't crashed. On ver...