title: Push View Controller When Push Notification Received iOS
body: <p>I have an app that uses XIB and not Storyboard.  The rootViewController is a TabBarController.  There are 5 tabs, and each tab contains a NavigationController.  What I would like to do, is have the app PUSH a certain view controller whenever the user taps on a received Push Notification.  In my didFinishLaunchingWithOptions I have (amongst other setup things):</p>
  
  <pre><code> window.rootViewController = self.tabBarController;
      [window makeKeyAndVisible];
  </code></pre>
  
  <p>In later code:</p>
  
  <pre><code>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
      [PFPush handlePush:userInfo];
      if (application.applicationState == UIApplicationStateInactive) {
          [self handleRemoteNotificationWithPayload:userInfo];
      }
  }
  -(void)handleRemoteNotificationWithPayload:(NSDictionary *)payload {
     NSLog(@"User tapped notification");
      NewsViewController *dvController8 = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:[NSBundle mainBundle]];
          [self.tabBarController.navigationController pushViewController:dvController8 animated:YES];
  
  
  }
  </code></pre>
  
  <p>However, nothing at all happens when I tap the notification, though the NSLog does fire in the console.  Suggestions?</p>
  
  <p>BASED off an answer, I now have</p>
  
  <pre><code>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
      [PFPush handlePush:userInfo];
      UINavigationController *nav = (UINavigationController *) self.tabBarController.selectedViewController;
      NewsViewController *dvController8 = [[NewsViewController alloc] initWithNibName:@"NewsViewController" bundle:[NSBundle mainBundle]];
      [nav pushViewController:dvController8 animated:YES];
  
  }
  </code></pre>
  
  <p>But this only works if the app is already running suspended in background.  If it has crashed or user has forced it close from app switcher, it will just open the app, and not push the controller.</p>
  
  <p>EDIT:</p>
  
  <p>Here is the <code>didFinishLaunchingWithOptions</code> method:</p>
  
  <pre><code>UIUserNotificationType userNotificationTypes = (UIUserNotificationTypeAlert |
                                                      UIUserNotificationTypeBadge |
                                                      UIUserNotificationTypeSound);
  
  
  
      UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:userNotificationTypes
                                                                               categories:nil];
  
      [[UIApplication sharedApplication]
       registerUserNotificationSettings:settings];
      [application registerUserNotificationSettings:settings];
      [application registerForRemoteNotifications];
  </code></pre>