Search code examples
iphoneiosbackgroundapple-push-notificationsforeground

How can I know if my apps come from background or are already in foreground


I want to handle APNs differently whether my application come from background or is already in the foreground. Do you know what methods could help me ?


Solution

  • These are the messages that handle the notification about a changing application state.

    – application:didFinishLaunchingWithOptions:
    – applicationDidBecomeActive:
    – applicationWillResignActive:
    – applicationDidEnterBackground:
    – applicationWillEnterForeground:
    – applicationWillTerminate:
    – applicationDidFinishLaunching:
    

    You must implement the one's you need in the designated Delegate! Take a look at the "Task" section of the following link for further assistance, especially the "Monitoring application state changes" part ;-)

    Apple's UIApplicationDelegate Protocol Reference