我有一个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] [我的问题] –