Skip to content
This repository has been archived by the owner on Sep 11, 2022. It is now read-only.

ViewController lost reference when push notification was being clicked and when the app was in background too #247

Open
rafameyer opened this issue Oct 25, 2018 · 0 comments

Comments

@rafameyer
Copy link

  1. App is in Background

  2. Push notification is received and clicked

2-1

  1. App will open and be redirect to the SecondViewController and the back button is clicked

3-1

  1. When click to the back button from SecondViewController and back to FirstViewController the "Menu" loss the reference from MenuViewController

4-1

My Code:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    if (application.applicationState == UIApplicationStateActive) {
        .......
    } else {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        UINavigationController *navigationController=[[UINavigationController alloc] init];
        self.window.rootViewController = nil;
        self.window.rootViewController = navigationController;

        MenuViewController *menuViewController = [storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
        [navigationController pushViewController:menuViewController animated:NO];

        HomeViewController *homeViewController = [storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
        [navigationController pushViewController:homeViewController animated:NO];

        AllNewsNotificationViewController *allNewsNotificationViewController  = [storyboard instantiateViewControllerWithIdentifier:@"AllNewsNotificationViewController"];
        [navigationController pushViewController:allNewsNotificationViewController animated:YES];

        [self.window makeKeyAndVisible];
    }

My MenuViewController impl:

@implementation MenuViewController

- (id)init {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    self = [storyboard instantiateViewControllerWithIdentifier:@"MenuViewController"];
    
    if (!self) {
        return self;
    }
    
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.homeViewController];
    
    NSDictionary *options = @{
                              PKRevealControllerRecognizesPanningOnFrontViewKey : @YES,
                              PKRevealControllerDisablesFrontViewInteractionKey : @NO
                              };
    
    self.revealController = [SubviewPKRevealViewController revealControllerWithFrontViewController:self.navigationController leftViewController:self options:options];
    self.revealController.revealDelegate = self.homeViewController;
    
    // The target view controller must implement this method
    self.navBarGesture =  [[UIPanGestureRecognizer alloc] initWithTarget:self.homeViewController action:@selector(menuPan:)];
    [self.navigationController.navigationBar addGestureRecognizer:self.navBarGesture];
    self.view.backgroundColor = [[Configurations sharedInstance] menuBackgroundColor];
    _topView.backgroundColor = [[Configurations sharedInstance] navegationbarBackgroundColor];
    
    return self;
}

Menu shortcut (button) from MenuViewController lost the reference and doesn't works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant