Open view controller when receiving remote Push Notification

自闭症网瘾萝莉.ら 提交于 2019-11-30 20:11:55
Paramasivan Samuttiram

Please try the following code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
    NotificationViewController *notificationViewController = [[NotificationViewController alloc] init];
    [navController.visibleViewController.navigationController pushViewController:notificationViewController];    
}

My code differs a bit from the answers I have seen. The fact is that the only code that works form me, is the following:

    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle: nil];

    IniciarSliderViewController *controller = (IniciarSliderViewController*)[mainStoryboard instantiateViewControllerWithIdentifier: @"MenuSlider"];

   [navigationController pushViewController:controller animated:YES];

1.- Instantiate de navigationController. Usually the rootviewcontroller in the vast majority of the cases, but not in all

2.- Instantiate the storyboard. Usuarlly tagged as MainStoryboard

3.- Instantiate your specific view controller. You must adapt for your special case

4.- Push as you should do because you've set all you need

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!