我很困惑在哪种情况下调用了哪些iOS委托方法:
- (void)applicationWillResignActive:(UIApplication *)application {
}
- (void)applicationDidEnterBackground:(UIApplication *)application {
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
}
- (void)applicationWillTerminate:(UIApplication *)application {
}
我已经尝试过乱搞他们,因为我希望我的应用程序在按下主页按钮之前立即执行某些操作,并在应用程序重新打开时执行一次。任何人都可以给我一个快速摘要,了解何时使用这些/何时在我的应用程序中调用它们?
答案 0 :(得分: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:.
}
答案 1 :(得分: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.
}