0

I'm trying to open child view(PostReaderViewController, the fourth view on Image ) when application is lunched through Push notification It's. Storyboard Image : enter image description here This is my Code :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      ... 
    //Detecting if the app was lunched by clicking on push notification :
    NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];

    if(apsInfo) {
        UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        PostReaderViewController* postReader = (PostReaderViewController *)[mainstoryboard instantiateViewControllerWithIdentifier:@"postReaderView"];
        CostumSDPost *tempPost = [[CostumSDPost alloc] init];
        tempPost.ID = userInfo[@"post_id"];
        postReader.thePost = tempPost;
        [self.window.rootViewController presentViewController:postReader animated:YES completion:NULL];
        //userInfo[@"post_id"]);
    }
    return YES;
}

When I launch my APP via push notification no error are shown but unfortunly it start and show the default View (third View on image).
Note that I'm using SWRevealMenu and the Intial Point (first View on image) is the Reveal View Controller

Chlebta
  • 3,090
  • 15
  • 50
  • 99

2 Answers2

0

self.window.rootViewController needs to perform the presentation in either viewDidLoad or in viewDidAppear. If you do it earlier then either rootViewController will be nil or the view controller hierarchy won't be in a state that can accommodate a presentation.

InkGolem
  • 2,662
  • 1
  • 15
  • 22
0

To slove This issue :

First I've created Global BOOL variable then in the AppDelegate I set this var to YES if app is lunched via push notif like this :

//Detecting if the app was lunched by clicking on push notification :
    NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    if(apsInfo) { 
        // Set my global Var to YES
        GlobalSingleton *global = [GlobalSingleton sharedInstance];
        global.displayFirstPost = YES; }

Then In my Home screen I check if this variable == YES then navigate to next screen auto else show the Home screen :

GlobalSingleton *global = [GlobalSingleton sharedInstance];
             if (global.displayFirstPost) {
                 // NAvigation code to the third Screen
                 }
Chlebta
  • 3,090
  • 15
  • 50
  • 99