title: Passing data received from a push notification from the AppDelegate to a ViewController
body: <p>In my app, there's a collection view displaying a set of images retrieved from a web service. Each image has tags. So the app has the ability to filter images using tags as well.</p>
  
  <p>Now I'm trying to add push notifications to this app. A push notification is sent when new images have been added to the server. These images are tagged  say, <strong>latest</strong>. I'm passing that tag as the message via a push notification and what I need is when the user taps on the push notification to open the app, it should load the latest new images to the collection view.</p>
  
  <p>I'm half way done. I receive the push notification with the message successfully to the <code>didReceiveRemoteNotification</code> method in the <code>AppDelegate.m</code> file. Now I need to pass it on to the view controller where the collection view is. I'm stuck at this point. I can't figure out how to send it over to the view controller.</p>
  
  <p>I tried declaring a property in the App delegate, assign the message value to it and referring it from the view controller but it didn't work. I tied delegates, notification center, user defaults but nothing worked.</p>
  
  <p>Can anyone please tell me how to accomplish this?</p>
  
  <p>Thank you.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>Here's my code. The last method I tried was the local notifications.</p>
  
  <p><strong>AppDelegate.m</strong></p>
  
  <pre><code>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
  {
      [[NSNotificationCenter defaultCenter] postNotificationName:@"PushNotificationMessageReceivedNotification" object:nil userInfo:userInfo];
  }
  </code></pre>
  
  <p><strong>ViewController.m</strong></p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated
  {
      [super viewWillAppear:animated];
  
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(remoteNotificationReceived:) name:@"PushNotificationMessageReceivedNotification"
                                                 object:nil];
  }
  
  - (void)remoteNotificationReceived:(NSNotification *)notification
  {
      NSLog(@"Notification: %@", notification.userInfo);
      NSString *msg = [[notification.userInfo valueForKey:@"aps"] valueForKey:@"alert"];
      self.label.text = msg;
  }
  </code></pre>