2011-05-25 92 views
0

當我們點擊iPhone上的主頁按鈕(即應用程序在後臺運行時)時,調用的方法順序是什麼。應用程序在後臺運行 - 在運行應用程序時點擊主頁按鈕

基本上,我想在我的應用程序進入後臺之前進行服務器調用。我在applicationWillResignActive:中編寫我的服務器調用代碼,但有時會執行,有時不會。

我需要一個解決方案。

+0

什麼設備是'applicationWillResignActive:'不叫呢?如果它是一個非多任務設備,那麼就不會調用,您需要'applicationWillTerminate:'來代替。 – 2011-05-25 23:51:46

+0

這是正確的電話。 applicationWillTerminate:被調用?您的UIApplicationExitsOnSuspend始終設置爲否? – Rayfleck 2011-05-25 23:52:50

+0

嘗試applicationDidEnterBackground。另外,雖然模擬器和設備通常在重新打開時恢復我的調試會話,但這並不一致。 – 2011-05-26 00:07:33

回答

0

從應用程序的委託文件本身:

- (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, called instead of applicationWillTerminate: when the user quits. 

    Superclass implementation saves changes in the application's managed object context before the application terminates. 
    */ 
    [super applicationDidEnterBackground:application]; 
} 

嘗試使用這種方法.....