2011-05-19 96 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

相关问题