1

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

Ahmed Abdallah
  • 2,338
  • 1
  • 19
  • 30
Aashish Nagar
  • 1,207
  • 1
  • 14
  • 30

2 Answers2

0

Just implement in your AppDelegate the method

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo;
ObjectAlchemist
  • 1,109
  • 1
  • 9
  • 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,937
  • 1
  • 13
  • 18
  • 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