2012-01-30 71 views

回答

3

我相信,你應該通過以下方法一次。

- (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. 
    */ 
} 

你放在applicationWillTerminate的代碼,把它放在上面提到的方法..
嘗試把你的代碼的方法之一&檢查你的邏輯工作與否。

編輯

你質疑規定,要檢測的應用程序強制退出事件 - 這是不可能的。 (抱歉,但不能在我手中)

我們通過雙擊從最小化狀態刪除應用程序的方式 - 這實際上意味着,我們力在quiting這些應用&這不會引發任何的我們的應用程序的方法爲我們的應用程序是將會被殺死。

+0

謝謝,但我想在關閉應用程序時立即獲得。 – damacri86 2012-01-30 12:46:32

+0

@ damacri86 - 那麼你應該使用'applicationWillResignActive' - 這會立即觸發。 – 2012-01-30 12:48:24

+0

再次感謝@Spark,但它不會在應用程序從跳板關閉時調用:( – damacri86 2012-01-30 12:55:59

1

當你說關閉你的意思是:當一個應用程序從最近使用的欄(雙按home鍵)關閉。

當用戶關閉你的應用程序時,你無法檢測到,因爲操作系統只會殺死你的應用程序。這不是封閉的,並且正在調用close方法。

+0

謝謝,你確定在這種情況下該方法不被稱爲? – damacri86 2012-01-30 12:44:49

0

當您按Home按鈕時,應用程序不會退出/退出。它只是進入背景。所以applicationWillTerminate沒有被調用。

按主頁按鈕兩次以驗證應用程序是否關閉。

還猜測星火的答案

+0

是的我知道,但是我想要在關閉應用程序時按下主頁按鈕兩次 – damacri86 2012-01-30 12:45:24

相關問題