Question

With iOS 5 and storyboarding, what is the best way to present a view when the user enters the app after having received a localnotification?

I have read that using the NSNotificationCenter is the way to do it but is that also so with storyboarding and segues?

Was it helpful?

Solution

This is exactly how I implemented it. In the AppDelegate's didFinishLaunchingWithOptions: method, I did the following:

   UILocalNotification *notification = 
   [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
   [self application:application didReceiveLocalNotification:notification];

I did this so that I could keep logic in a single place. In the didreceiveLocalNotification: method, I then used the NSNotificationCenter:

    // Let another view handle the display        
    NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
    [nc postNotificationName:@"SHOW_VERSE" 
                      object:self 
                    userInfo:notification.userInfo];

The view that handles the display is the first UIViewController for the Storyboard. In that class, in the viewDidLoad method:

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

This works very well for me. Hope it helps.

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