0

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?

4

2 回答 2

1

Apple 自己的描述是最好的,你会在 Xcode 的每个模板应用程序中找到它。

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application
{
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}
于 2012-07-13T17:24:19.037 回答
0
- (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.
    }
于 2012-07-13T17:25:15.403 回答