Search code examples
ioslifecycle

Where do I put logic for when an iOS application hard closes and comes back?


I have an iOS application where I need to persist a set of data after the application HARD CLOSES (when the user double clicks the Home button and slides the application upwards). Then, when the application comes back to the foreground, I need to fetch that data and do something with it. I'm just not sure where I need to put that logic for Application Hard Close and Resuming the Application.


Solution

  • In your AppDelegate

    When your app is going to be closed, but still in Multitasking menu the following method is getting called

    -(void)applicationWillResignActive:(UIApplication*)application
    

    If after 3 minutes user doesn re-open your app this method is going to be called

    -(void)applicationDidEnterBackground:(UIApplication*)application
    

    If user re-opens your app from multitasking menu the following method is getting called

    -(void)applicationWillEnterForeground:(UIApplication*)application
    

    If user is going to close your app from multitasking menu this method is getting called(you will have limited time to perform some logic here)

    -(void)applicationWillTerminate:(UIApplication*)application