Search code examples
iosios5apple-push-notifications

iOS Push Notification Redirect to View when App becomes Active


Is there any way to redirect to a View once the user opens the App from the Notification Center considering that the App was just launched before the action. (App is still running in the background)

Example, I launch the App normally, press the home button. Then I received a number of remote notifications, and then I open the app anywhere from that push notification.

Since I have different push notifications that could redirect to any part of my App. I want that the redirect would still work not only in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

is it possible that I could still access the remote notification (json data within) during application becomes active? so that I could do some redirection. And also, so that the user can just run through the remote notifications he have in the center, and will be redirected to the proper view depending on what notification the user tapped.

Update

Another Example:
(1)User receives the 2 push notifications in application: didReceiveRemoteNotification:
(2)User is redirected with the first push notification.
(3)User goes to his notification center
(4)taps the other notification. Will he still be redirected? I don't think the app won't go inside in either application:didReceiveRemoteNotification: or application: didFinishLaunchingWithOptions:


Solution

  • Yes, you can, here is a simple outline/sample

    -(void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
     {
          //When notification is pressed on background it will enter here
    
          //Get strings based on information on your json payload for example
          if([[userInfo objectForKey:@"keyword"] isEqualToString:@"value"]){
               //redirect/push a screen here for example
          }
     }