aznelite89 aznelite89 - 3 months ago 10
Objective-C Question

able redirect to specify view controller after clicked remote notification but only VC but without navigation bar

i had setup an redirect after user click the push notification and it did worked. However the app is redirect to the View Controller without navigation bar and bottom toolbar.. Below are my redirect code : -

// Did receive notification method here...

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo NS_AVAILABLE_IOS(3_0)
{
NSLog(@"user info1 is %@",userInfo);


[[NSNotificationCenter defaultCenter] postNotificationName:@"NOTIFICATION_RECIEVED"
object:nil
userInfo:nil];

UIStoryboard *mainsboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [mainsboard instantiateViewControllerWithIdentifier:@"notice"];
[self.window.rootViewController presentViewController:vc animated:YES completion:nil];


This screenshot showing the notice storyboard properties

Answer

I think I understand the question to mean that you expect the view controller to appear in the context of a navigation controller that you have configured in storyboard. In that case, you'll need to do a little more to set things up:

  1. find the navigation controller in your storyboard that contains the one with the "notice" ID, and give it a storyboard ID, too -- maybe something like "noticeNavigationController"

  2. upon receiving the notification, build navigation controller from storyboard, too, and set it's root with the "notice" view controller that you know how to build...

    // as you have it
    UIStoryboard *mainsboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [mainsboard instantiateViewControllerWithIdentifier:@"notice"];
    
    // but now build a navigation controller, too
    UINavigationController *navVC = [mainsboard instantiateViewControllerWithIdentifier:@"noticeNavigationController"];
    // make your vc the root
    navVC.viewControllers = @[ vc ];
    
    // and present** that navigation controller
    [self.window.rootViewController presentViewController: navVC animated:YES completion:nil];
    

**Note, unless you're doing a presentation intentionally for some reason, it's more commonplace to just set the app's rootViewController to the navVC, rather than present it.