【问题标题】:iOS: disconnected when in inactive state?iOS:处于非活动状态时断开连接?
【发布时间】:2011-05-19 09:47:31
【问题描述】:

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

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

谢谢

**编辑**

In the official documentation我读过这个:

准备好处理连接 基于网络的故障 插座。系统可能会崩溃 套接字连接,而你 申请暂停任何 数量的原因。只要你的 基于套接字的代码已准备好 其他类型的网络故障,例如 作为丢失的信号或网络 过渡,这不应该导致 任何不寻常的问题。当你的 应用程序恢复,如果遇到 使用套接字时失败,简单地说 重新建立连接。

这意味着处于非活动状态的 iOS 可以断开我的连接?谢谢

【问题讨论】:

  • 您对文档的引用是关于背景状态,而不是非活动状态。他们根本不一样!

标签: iphone cocoa-touch ios background connection


【解决方案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.
     */
}

【讨论】:

  • 为了澄清代码中的注释(顺便说一下,直接来自 Xcode 项目模板):虽然在某些情况下禁用计时器等对于应用程序开发人员来说是不活动的,但系统将不会自动这样做。
  • 但是你确定在非活动状态下连接不会中断吗?
  • 不确定,但很有信心。试试看!
  • 想一想:我确定。我们有很多后台通信正在运行,它们在非活动模式下愉快地继续。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-07-08
  • 2016-08-19
  • 2012-01-03
  • 2021-09-13
  • 2013-08-27
  • 2019-09-01
  • 2018-05-25
相关资源
最近更新 更多