Trouble segue-ing to a uiviewcontroller from appDelegate upon UILocalNotification - with SWRevealViewController in the mix

纵饮孤独 提交于 2019-12-23 03:03:24

问题


I'm using iBeacons and am trying to respond to the UILocalNotifications they trigger. Everything works fine there and I'm able to display my message content in the notification.

I want to be able to launch a specific UIViewController when the user swipes the notification. Currently, according to NSLog output, I'm very close.

The tricky bit is that I'm using SWRevealViewController for its cool slider-window menu features and so the segue is crapping out and saying,

*** Assertion failure in -[MainHomePageVC prepareForSegue:sender:], /nmaster/nmaster/MainHomePageVC.m:312
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'oops! must have a revealViewController'

I'm responding to the localnotification triggers inside my appDelegate.m and so am trying to segue from there, first to the UIViewController that has the storyboard segue to the UIViewController I want to goto. So I've got one level of indirection going on here which seems to be complicating things further. Within the appDelegate, I get a pointer to the main UIViewController and then I try and initiate a segue from that object to the UIViewController I'm interested in showing.

Here is the code in my appDelegate.m

// this routine is called when an ibeacon range entry/exit is detected

-(void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {NSLog(@"yeehaw - you found an iBeacon!");

UIApplicationState state = [application applicationState];
if (state == UIApplicationStateInactive) {

    //push view manually
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    MainHomePageVC *ivc = [storyboard instantiateViewControllerWithIdentifier:@"mainmenu"];
    [ivc.revealButtonItem setTarget: ivc.revealViewController];
    [ivc.revealButtonItem setAction: @selector( revealToggle: )];
    [ivc.navigationController.navigationBar addGestureRecognizer: ivc.revealViewController.panGestureRecognizer];
    [ivc.navigationItem setHidesBackButton:YES];
    ivc.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:ivc.revealButtonItem, nil];
    [ivc performSegueWithIdentifier:@"foodmenu" sender:ivc];
}

And here is the standard SWRevealViewController code in the main UIViewcontroller that I have instantiated in the code above.

- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{
    // configure the segue.
    if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] )
    {
        SWRevealViewControllerSegue* rvcs = (SWRevealViewControllerSegue*) segue;

    SWRevealViewController* rvc = self.revealViewController;
    NSAssert( rvc != nil, @"oops! must have a revealViewController" );

    NSAssert( [rvc.frontViewController isKindOfClass: [UINavigationController class]], @"oops!  for this segue we want a permanent navigation controller in the front!" );

    rvcs.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc)
    {
        NSLog(@"ok, time ___ todo my thing ___");
        UINavigationController* nc = [[UINavigationController alloc] initWithRootViewController:dvc];
        [rvc setFrontViewController:nc animated:YES];


       };
    }
}

Notice that the "oops!" error message from the assertion above is the one I'm getting.

Can anyone tell me why I am failing this assertion?

来源:https://stackoverflow.com/questions/21884926/trouble-segue-ing-to-a-uiviewcontroller-from-appdelegate-upon-uilocalnotificatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!