1

I've searched around the Internet and stack overflow and still can't solve this problem.

It is a tabbed application template.

When the app isn't running and it receives a push notification I want to read the contents of launchOptions from

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions which I do by parsing the JSON data etc...

I then want to display this on a separate view on storyboard.

I've read on some posts to do:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; DetailViewController *ivc = [storyboard instantiateViewControllerWithIdentifier:@"Detail"]; [(UINavigationController*)self.window.rootViewController pushViewController:ivc animated:NO];

but this is giving me

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITabBarController pushViewController:animated:]: unrecognized selector sent to instance 0x1c5a0c20'

When the app is running in the background and it receives the push from

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)notification I call [[NSNotificationCenter defaultCenter] postNotificationName:@"receivedPushNotification" object:self];

which tells whatever view is currently being displayed to

detail = [self.storyboard instantiateViewControllerWithIdentifier:@"Detail"]; [self.navigationController pushViewController:detail animated:YES];

which works fine.

The problem is none of these views are loaded when the app first launches so I need a way of putting the detail view controller on the users screen from appDelegate.

Thanks

JavaWizKid
  • 69
  • 1
  • 8

1 Answers1

0

I assume your storyboard is set as the "mainstoryboard"(key UIMainStoryboardFile in your Info.plist).In that case, UIKit will load the storyboard and set its initial viewcontroller as your window's root view controller before it sends application:didFinishLaunchingWithOptions: to your AppDelegate.I also assume that the initial viewcontroller in your storyboard is the navigation controller, on which you want to push your main or loginview controller.

You can ask your window for its root view controller, and send the performSegueWithIdentifier:sender: message to it:

NSString *segueId = success ? @"pushMain" : @"pushLogin";
[self.window.rootViewController performSegueWithIdentifier:segueId sender:self];
Steve
  • 1,022
  • 2
  • 9
  • 30