I’m using storyboard , and I want to open always the same view when user receives remote push notifications, even the app is in background or opened. The view I need to present is four views after the initial view controller set in the storyboard. I read this posts:
How can I show a modal view in response to a notification as a new window? (no parent vc)
Open a specific tab/view when user receives a push notification
So here is my code:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
notificacionViewController *menu = [navController.storyboard instantiateViewControllerWithIdentifier:@"notificacion"];
// First item in array is bottom of stack, last item is top.
navController.viewControllers = [NSArray arrayWithObjects:menu,nil];
[self.window makeKeyAndVisible];
}
But when I receive notification, the app crashes with this error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[locationViewController setViewControllers:]: unrecognized selector sent to instance 0x42ccd0'
locationViewController is the view controller set as initial in the storyboard.
Many thanks.
Please try the following code: