Launching a specific viewController in response to a remote push notification Launching a specific viewController in response to a remote push notification ios ios

Launching a specific viewController in response to a remote push notification


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

-(void)gotoback{    AppDelegate *delegate =(AppDelegate *)[UIApplication sharedApplication].delegate;    if(delegate.gotNotifcation)    {        delegate.gotNotifcation = NO;        MessageListController *feed = [[MessageListController alloc] init];        [self.navigationController pushViewController:feed animated:NO];    }    else    {        [self.navigationController popViewControllerAnimated:NO];    }}