1

I build and app that has Background Modes enabled, and the push notification payload that the app gets has "content-available" key.

This setup results in didReceiveRemoteNotification being called EVERY TIME the app gets a push notification, which means that if i get 3 push notifications while the app is in the background - the function will fire 3 times and the code inside it will be executed when the app will applicationDidBecomeActive

My biggest problem is that there is NO way to know if a user tapped the Push System Alert or tapped the app icon to bring the app from background, since regardless of the user's action, the didReceiveRemoteNotification will fire.

Is there a way to know for sure that the user tapped on the Sys alert?

and this: http://samwize.com/2015/08/07/how-to-handle-remote-notification-with-background-mode-enabled/ and other answers don't seem to be helpful

Tim Friedland
  • 1,045
  • 11
  • 18

1 Answers1

-1
For app is background push 
- (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
    }
}

For app is terminate state

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

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

    }
}
Optimus
  • 800
  • 5
  • 16
  • Dear sir, unfortunately your answer can not solve my problem, since, as my question states, there is NO WAY of distinguishing between the user tapping the notification alert and the `didReceiveRemoteNotification` in general. Because with the BackgroundMode enabled `didReceiveRemoteNotification` is called for EVERY push notification that is received. So if I get 3 pushes and the app is in background and I tap the app **icon** the `didReceiveRemoteNotification` is called **THREE TIMES** – Tim Friedland Mar 15 '17 at 06:59