2012-07-13 48 views
0

我很困惑,其中这些iOS的委托方法被称为在哪些情况:什么时候调用每个这些iOS背景委托方法?

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


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


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


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


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

我试着跟他们瞎搞,因为我想我的应用程序做一些动作退出权之前,如果home键是当应用程序重新打开时,它也会被压缩。任何人都可以给我一个快速总结何时使用每一个/当他们在我的应用程序中调用?

回答

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. 
    } 
+0

谢谢!我知道这些可能看起来很基本,但很难理解什么时候每一个都会发生。 – MrHappyAsthma 2012-07-13 17:30:06

+1

我相信applicationWillResignActive(及其对应的应用程序DidBecomeActive)也会在打电话时或当有其他系统中断时调用。 – 2012-07-15 21:37:27

1

苹果自己的描述是最好的,你会发现它在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:. 
} 
+0

这些都是有我的模板,但我很新的这东西,我发现他们有一点复杂。我不明确何时“终止”和“进入背景”等等。 – MrHappyAsthma 2012-07-13 17:29:37

相关问题