我有一個voip應用程序,它在後臺運行不斷。 雖然我在後臺我正在從主線程調用:(建立網絡連接,以防我診斷網絡丟失)。PerformSelector延遲後不運行在後臺模式 - iPhone
[self performSelector :@selector(Reconnect:) withObject:nil afterDelay:60.0];
但是,選擇器只在我的應用程序返回到前景時執行。 我應該做什麼特別讓選擇器在後臺執行嗎?
感謝
編輯:
-(void) reconectInBackgroundAfterDelay:(NSTimeInterval) dealy
{
NSLog(@"reconectInBackgroundAfterDelay");
UIApplication* app = [UIApplication sharedApplication];
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
}];
// Start the long-running task and return immediately.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[self performSelector :@selector(Reconnect:) withObject:nil afterDelay:dealy];
[app endBackgroundTask:bgTask];
bgTask = UIBackgroundTaskInvalid;
});
}
我加入這個代碼,而不是,但仍然是「重新連接」的方法是沒有得到所謂的提供延遲之後。 我在後臺調用「reconectInBackgroundAfterDelay」方法。
其他建議?
編輯2 找到了解決辦法。見下面
非常感謝,它運作良好。 – 2011-11-01 06:34:40
我的應用程序也是voip應用程序。但最初我的應用程序在註冊之前先從服務器上下載文件。是否有可能使用您的解決方案繼續下載。 –
這裏是[http://stackoverflow.com/questions/14828955/download-files-using-http-request-in-background-in-iphone-above-ios-4-0#comment20777172_14828955] [我的問題] –