Set view controller through applicationDidfinidhLaunchingWithOption method without hiding tabbar.

| | August 11, 2015

I have comment view controller which i want to open through applicationDidfinidhLaunchingWithOption when notification clicked also i need to set comment property in didFinishLWithOption.after comment view controller i should able to on lifeLine(First) Tab.

UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
    if (localNotif) {
//what code i should write to open comment view controller and on back button i will be on lifeline (first viewcontroller)
}

enter image description here

Thanks in advance.

One Response to “Set view controller through applicationDidfinidhLaunchingWithOption method without hiding tabbar.”

  1. You have to place your UITabBarController in a UINavigationController in your AppDelegate. Once you do this, then you declare the rootViewController of your application’s main window a UINavigationController. Declare this in your header file of your AppDelegate:

     @property (nonatomic, strong) UINavigationController * mainWindowRootViewController;
    

    Then do this:

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [_window makeKeyAndVisible];
        _mainWindowRootViewController = [UINavigationController new];
        [self.window setRootViewController:_mainWindowRootViewController];
    ///code code code
        [_mainWindowRootViewController setViewControllers:@[splashScreen, tabBarController] animated:TRUE];
    
        ...//code code code
        return YES;
    }
    

    Now that you have your mainWindowRootViewController holding your splashScreen as the it’s rootViewController and your tabBarController as the second viewcontroller on the stack, you can do this:

    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (localNotif) {
            UIViewController * commentsViewController = [UIViewController new];
            UINavigationController * tempNAV = [[UINavigationController alloc] initWithRootViewController:commentsViewController];
            [_mainWindowRootViewController presentViewController:tempNAV animated:TRUE completion:nil];
    }
    

    When you present the comments view controller, it will be presented over the entire stack of controllers including the UITabBarController and the splashScreen (if you have a splash screen). Also, to all the people who may say, “you can’t present a UINavigationController with a UINavigationController”, yes you can, try it for yourselves, it’s amazing!

    This assumes you have the comments view controller declared in the AppDelegate, if you have declared this “localNotif” somewhere else, then you can do this same presentation OVER the entire STACK of view controllers over the entire app window by using the following modifications:

    UILocalNotification *localNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (localNotif) {
            UIViewController * commentsViewController = [UIViewController new];
            UINavigationController * tempNAV = [[UINavigationController alloc] initWithRootViewController:commentsViewController];
           [[(YOURAppDelegate *)[UIApplication sharedApplication].delegate mainWindowRootViewController] presentViewController:tempNAV animated:TRUE completion:nil];
    }
    

Leave a Reply