在iPhone的后台使用http请求下载文件(iOS 4.0以上) [英] download files using http request in background in iPhone (above iOS 4.0)

查看:239
本文介绍了在iPhone的后台使用http请求下载文件(iOS 4.0以上)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS新手。
我想知道我的申请的一些基本需求是否可能?
当我的应用程序启动时(点击我的应用程序图标),应用程序应该从服务器下载一些5-10个文件。如果按下主页按钮,它应该继续在后台下载。我的应用程序有重试逻辑即如果服务器无法访问且请求超时,则应用程序将等待一段时间并一次又一次地发送请求,直到下载完成。
有可能吗?

I am new to iOS. I want to know some basic need for my application is possible or not? "When my application starts (tapping on my application icon), app should download some 5-10 files from server. It should continue its downloading in background also if "Home" button is pressed. And my app has retry logic i.e. if server is unreachable and request timeout occurred then app will wait for some time and send request again and again till downloading completed." Is it possible?

推荐答案

那么你应该做的是在app delegate didFinishLaunchingWithOptions:中,你问它进行nsurlrequest(或类似于开源框架的东西)。此外,自己编写重试逻辑并不困难。一种常见的方法是指数退避,这意味着你等待2,4,8,16等毫秒,然后在某些时候你显示一个UIalertview,如果它看起来像服务器真的停了一段时间(如果你遇到了一定的话)退避,停止尝试)。

So what you should do is either in the app delegate didFinishLaunchingWithOptions:, you ask it to make an nsurlrequest (or something similar from an open source framework). Also, it isn't hard to code retry logic yourself. A common method is exponential backoff, meaning that you wait 2, 4, 8, 16, etc. milliseconds, and then at some point you display a UIalertview if it looks like the server is really down for a while (if you hit a certain backoff, stop trying).

为了在应用程序进入后台时处理该应用程序,该应用程序也在应用程序委托中。

For dealing with the application when it enters the background, that's also in the app delegate.

这篇关于在iPhone的后台使用http请求下载文件(iOS 4.0以上)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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