Question

I have a storyboard app with loads of (~45) uiviewControllers. Whether in background or foreground, when a beacon triggers a uilocalnotification and the user accepts it, I want to "push/segue" to the UIViewController associated with that beacon trigger. Simple enough. Depending on the beacon, I have approx 10 different VCs that I would segue to.

The question I have is this. The user could literally be sitting at any one of my 45 UIViewCtrlers when the beacon triggers the notification so every one of my UIViewControllers has to have something similar to the below, (along with the code block for the selector), in order to act upon the notification and push/segue to another viewcontroller.

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(showFoodMenuViewNow)
                                             name:@"showfoodmenu" object:nil];

This is going to literally riddle my storyboard with more inter-VC push/segue connections than you could shake a stick at. Very messy. Is there some way to eliminate all the visual storyboard segues or somehow introduce a single 'vector viewcontroller' that all the views segue to. That VC would then evaluate the localnotification and push to the associated VC.

What is the recommended best practice for managing this?

Hope I'm making sense.

UPDATE:

I've switched paths now, trying to access the UINavigationController directly from my appDelegate. I'm using the following code to do that and, although my nc is not nil, no view is pushed...

Why would this code not push the desired viewcontroller?

UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
nm_vcFoodMenu *fm = [sb instantiateViewControllerWithIdentifier:@"foodmenu"];
UINavigationController *nc = [sb instantiateViewControllerWithIdentifier:@"myNavController"];
if (nc == nil){
    NSLog(@"nc is nil");
} else {
    NSLog(@"nc is not nil so trying to push to foodmenu");
    [nc pushViewController:(nm_vcFoodMenu *)fm  animated:YES];
}

This is a depiction of my storyboard and the various moving parts. Hoping this will help you help me! enter image description here

Thanks.

Was it helpful?

Solution

I do not claim to have a good solution for this, but below is what I do for what it's worth. I also would like to hear if anybody has a better solution.

  1. I manage iBeacon transitions programatically in my AppDelegate without any setup in the storyboard.

  2. I take special care that two iBeacons don't cause two transitions too closely in time to eachother (a minimum of a few seconds must have passed since the last transition, otherwise I delay the transition with a timer or suppress it.)

  3. Managing the stack in the navigation controller is a real pain. Only in specific cases where I know I want the user to be able to go back do I do a [navigationController pushViewController:newViewController animated:YES]. And in some cases I end up suppressing the back button in my ViewControllers with [self.navigationController setNavigationBarHidden:YES animated:YES];

Admittedly, all of this is really messy. But given the dynamic nature of how iBeacon-based transitions can happen, I think it is often hard to set up all the combinations ahead of time.

OTHER TIPS

In our project, we create dedicated singleton that plays as iBeacon delegate, and present our notification interface over top view controller, so all logic contains in one place and no need to make modification in other view controllers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top