2011-05-19 55 views
0

我正在分析一個應用程序的可行性。只是一個問題:iOS:處於非活動狀態時斷開連接?

當應用程序從活動狀態進入非活動狀態(睡眠或電源按鈕按下)我可以設置一個計時器和請求數據使用遠程http連接?恐怕處於非活動狀態的iOS會關閉所有連接:有一種方法可以在處於非活動狀態時阻止這種情況發生?

感謝

**編輯**

In the official documentation我讀過這樣的:

準備處理連接 失敗在基於網絡的 插座。該系統可能會拆除 套接字連接,而您的 應用程序因任意 原因而被暫停。只要您的 基於套接字的代碼爲 準備了其他類型的網絡故障,例如 作爲丟失信號或網絡 轉換,這應該不會導致 任何異常問題。當您的 應用程序恢復時,如果在使用套接字時遇到 失敗,則只需 重新建立連接。

這意味着在Inactive狀態下iOS可以拆除我的連接?謝謝

+0

你使用線程嗎? – 2011-05-19 09:54:11

+0

是的,如果需要的話 – Ricibald 2011-05-19 10:09:32

+0

你的文檔引用是關於背景狀態,而不是非活動狀態。他們是不一樣的遠射! – 2011-05-19 11:33:32

回答

1

與進入後臺不同,應用程序將繼續在非活動狀態下正常運行。

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

要澄清代碼中的註釋(順便提一下Xcode項目模板,順便說一句):儘管在應用程序開發人員處於非活動狀態時禁用定時器等有意義,但系統不會自動執行此操作。 – 2011-05-19 10:03:19

+0

但是你確定連接在不活動狀態下不會中斷嗎? – Ricibald 2011-05-19 10:14:59

+0

不確定,但相當有信心。試試看看! – 2011-05-19 10:19:08

相關問題