iOS:处于非活动状态时断开连接



我正在分析应用程序的可行性。只是一个问题:

当应用从活动状态变为非活动状态(按下睡眠或电源按钮)时,是否可以使用远程 HTTP 连接设置计时器并请求数据?恐怕在非活动状态下,iOS会关闭所有连接:有办法在处于非活动状态时防止这种情况?

谢谢

**编辑**

在官方文档中,我读过以下内容:

准备好处理连接 基于网络的故障 套接字。系统可能会拆卸 套接字连接,而您的 任何申请将被暂停 原因的数量。只要你的 准备了基于套接字的代码 其他类型的网络故障,例如 作为丢失的信号或网络 过渡,这不应该导致 任何不寻常的问题。当您的 应用程序恢复(如果遇到 使用套接字时出现故障,只是 重新建立连接。

这意味着在非活动状态下,iOS可以破坏我的连接吗?谢谢

与进入后台时不同,应用程序在非活动状态下继续正常运行。

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

最新更新