How can I differentiate between push notifications received in app and touched from outside the app?

apple-push-notifications, ios, push-notification

Solution

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
    if ( application.applicationState == UIApplicationStateActive )
        // app was already in the foreground
    else
        // app was just brought from background to foreground
    ...
}

Problem

I have push notifications setup in my app. I have the method: ``` - (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo { if() { //app is in foreground to get here } else if() { //app is in background and then the notification is clicked, to get here } } ``` I need to differentiate between touches of the notification outside the app, and simply receiving the notification in the app. Any help?

Original source