Search code examples
iphonebackgroundterminate

When are each of these iOS backgrounding delegate methods called?


I am confused which of these iOS delegate methods are called in which situations:

- (void)applicationWillResignActive:(UIApplication *)application {
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
}


- (void)applicationWillTerminate:(UIApplication *)application {
    }

I've tried messing around with them because I want my app to do some actions right before it exits if the home button was pressed and also once when the app re-opens. Could anyone give me a quick summary of when to use each one of these/when they are called in my app?


Solution

  • - (void)applicationWillResignActive:(UIApplication *)application {
    // Home button was pressed! Do some actions here!
    }
    
    
    - (void)applicationDidEnterBackground:(UIApplication *)application {
    // Your app is now running in the background. It is no longer visible.
    }
    
    
    - (void)applicationWillEnterForeground:(UIApplication *)application {
    // Your application was running in the background, but is now being re-opened
    }
    
    
    - (void)applicationDidBecomeActive:(UIApplication *)application {
    // You application is now once again active
    }
    
    
    - (void)applicationWillTerminate:(UIApplication *)application {
    // Your application is about to QUIT.
        }