iphone - 连接到服务器在后台 [英] iphone - Connecting to server in background

查看:112
本文介绍了iphone - 连接到服务器在后台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建它连接到服务器并发送一些文本的应用程序。
如果网络(包括WiFi或3G)是存在的,它会立即发送文本到服务器。
但是,如果没有网络,它不断轮询每5分钟服务器连接。
所有的这部分工作正常。

I'm creating an app which connects to server and sends some text. If network (both wifi or 3g) is there, it will immediately send the text to server. But if there is no network, it keeps on polling for server connection every 5 minutes. All this part is working fine.

但使用iPhone 4的设备时,我希望应用程序来检查服务器的连接,即使应用进入后台。因此,当应用程序进行到背景而当网络回来,它必须能够将文本发送至服务器

But when using iPhone 4 device, i want the app to check for server connection even when app goes into background. So, when app goes to background and when network comes back, it must be able to send the text to server.

我怎样才能实现呢?我见过一些应用程序,他们说,应用程序甚至会在后台把照片上传到服务器。他们会怎么做呢?

How can I achieve it? I've seen some apps where they say that the app will upload photos to server even in background. How will they do it?

推荐答案

我建议你仔细阅读这篇文章来自苹果,尤其是在完成有限长度的任务在后台部分。

I suggest you read this article from Apple carefully, especially the Completing a Finite Length Task in the Background section.

<一个href=\"http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html\">http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html

有得澄清:


  • 一旦你的应用程序在后台运行,并为冷冻由操作系统,就没有办法为你的应用程序的由它的自我,以唤醒,并重新连接到互联网。

  • 然而,根据文章以上来自苹果,你可以调用这个 beginBackgroundTaskWithExpirationHandler 从您的应用程序的委托方法申请更多的时间投入的背景下,这是说的时候,虽然你的应用程序无法通过它的自我醒来的背景下,它可以当,在后台,而不是冻结时,尝试申请额外的时间来完成其漫长的任务。

  • Once your app is in the background and is frozen by the OS, there would be no way for your app by it self to wake up and re-connect to the internet.
  • However, according to the article above from Apple, you can call this beginBackgroundTaskWithExpirationHandler method from your app's delegate to apply for additional time when put in the background, which is to say, though your app cannot wake up by it self when in background, it can, when in the background and not frozen, try to apply for additional time to finish its lengthy task.

希望它帮助。

这篇关于iphone - 连接到服务器在后台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆