2012-07-13 102 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

相關問題