2011-05-03 63 views

回答

0

使用- (void)applicationDidEnterBackground:(UIApplication *)application {}當您的應用程序進入後臺(home鍵)和- (void)applicationWillTerminate:(UIApplication *)application當它即將被關閉(開/關按鈕或iOS呼叫後臺隨機時間後關閉) 。

0

我的理解是,當你鎖定或解鎖你的iOS設備時,你的應用程序委託將分別調用- (void)applicationWillResignActive:(UIApplication *)application- (void)applicationDidBecomeActive:(UIApplication *)application。鎖定和解鎖與接聽電話等中斷類似。通過點擊主頁按鈕將應用程序發送到後臺會調用不同的方法,即- (void)applicationDidEnterBackground:(UIApplication *)application- (void)applicationWillEnterForeground:(UIApplication *)application

3

對於開/關按鈕(或者有來電或短信):

- (void)applicationWillResignActive:(UIApplication *)application 

對於Home鍵:

- (void)applicationDidEnterBackground:(UIApplication *)application 
1

隨着applicationWillResignActive通知,applicationDidBecomeActive仍然會在你進入正在進入背景。但是有一種方法可以通過獲取應用程序的狀態來區分,所以請在applicationDidEnterBackground中試試。

- (void)appHasGoneInBackground {  
    bool inBackground = [UIApplication sharedApplication].applicationState == UIApplicationStateBackground; 

    // lockScreen state 
    if (!inBackground) { 
     // do something 
    } 
} 

Apple's UIApplication-class reference

相關問題