繁体   English   中英

这些iOS背景代理方法中的每一个何时调用?

[英]When are each of these iOS backgrounding delegate methods called?

我很困惑在哪些情况下会调用以下哪些iOS委托方法:

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


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


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


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


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

我曾尝试与他们混为一谈,因为我希望我的应用程序在按下主屏幕按钮后立即退出之前执行一些操作,并且在应用程序重新打开时执行一次操作。 谁能给我快速总结一下何时使用这些应用程序/何时在我的应用中被调用?

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:.
}
- (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.
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM