Search code examples
iosobjective-cuilocalnotificationappdelegate

How to determine that app become active by tapping on local notification


  1. An app is running on iPhone and user tap the home button once and app will enter background.
  2. after 2 or 3 seconds local notification arrives and user tap on local notification.
  3. app will again enter in foreground and become active and didReceiveLocalNotification will be called.

How to determine that app become active by tapping on local notification not the app icon.


Solution

  • Here is an easy way to detect what's your App's status when UILocalNotification fired and if
    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
    is called, this makes sure that local notification is received.

    - (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
        UIApplicationState state = [application applicationState];
        if (state == UIApplicationStateInactive) {
            // Application was in the background when notification was delivered.
        } else {
    
        }
    }