user1780591
user1780591

Reputation: 207

Dismissing a viewController presented by a push notification

I'm presenting a testViewController as a rootViewController in didReceiveRemoteNotification which works perfectly. Then when I press the back button of testViewController (to go back to "mainViewController" which in this case is -dismissViewController-), nothing happens. I understand that this happens because of it was presented as a rootView.. and there is nothing to dismiss. How do I control from where or how did testViewController was presented in order to decide on how to proceed when the back button is pressed? I hope you understand what I am trying to say. Any advice would be helpful.

Thank you in advance

ChatViewController *chat = [[ChatViewController alloc] initWithNibName:@"ChatViewController" bundle:nil];

        [_window.rootViewController presentViewController:chat animated:YES completion:nil];

Upvotes: 0

Views: 476

Answers (1)

Igor
Igor

Reputation: 4848

You shouldn't set it as your rootViewController, but instead make your rootViewController present it as a modal view controller:

[self.window.rootViewController presentViewController:testViewController animated:YES completion:nil]

When you call the -dismissViewControllerAnimated:completion: message, it should go back to your rootViewController.

Upvotes: 2

Related Questions