1

I want to detect if user click on push notification to launch the app.or to get it in foreground.

Ahmed Abdallah
  • 2,081
  • 1
  • 16
  • 28
Aashish Nagar
  • 1,077
  • 1
  • 9
  • 27

2 Answers2

0

Just implement in your AppDelegate the method

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
ObjectAlchemist
  • 989
  • 1
  • 8
  • 18
0

If the application was not running the didFinishLaunchingWithOptions method gets called when the application starts and you can check the launchOptions parameters like this:

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

    if (launchOptions != nil) {
         NSDictionary *notification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
         if (notification) {
             // Launched from push notification
         }

    }
}

If the application is already launched you can use this method:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateInactive || application.applicationState == UIApplicationStateBackground  )
    {
         //opened from a push notification when the app was on background
    }
}

You can also check: Detect if the app was launched/opened from a push notification

Community
  • 1
  • 1
vbgd
  • 1,819
  • 1
  • 9
  • 17
  • What if application is already launched I need to handle both condition. – Aashish Nagar Jul 24 '16 at 10:24
  • if app is coming from background to foreground , at the same time if app receive push notification , that time I would get the state as InActive. ( How to solve this ? – Aashish Nagar Jul 24 '16 at 10:29