简体   繁体   English

在iPhone(iOS 4.0以上版本)中使用http请求在后台下载文件

[英]download files using http request in background in iPhone (above iOS 4.0)

I am new to iOS. 我是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 ie if server is unreachable and request timeout occurred then app will wait for some time and send request again and again till downloading completed." “当我的应用程序启动时(点击我的应用程序图标),该应用程序应该从服务器下载大约5-10个文件。如果按下“主页”按钮,它也应该在后台继续下载。而且我的应用程序具有重试逻辑,即服务器是否处于无法访问并且发生请求超时,那么应用将等待一段时间并一次又一次发送请求,直到下载完成。” Is it possible? 可能吗?

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). 因此,您应该做的是在应用程序委托didFinishLaunchingWithOptions:中,要求它发出nsurlrequest(或来自开源框架的类似操作)。 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). 常用的方法是指数补偿,这意味着您需要等待2、4、8、16等毫秒,然后在某个时刻显示UIalertview(如果服务器确实停机了一会儿)(如果您击中了某个退缩,请停止尝试)。

For dealing with the application when it enters the background, that's also in the app delegate. 为了在应用程序进入后台时对其进行处理,它也在应用程序委托中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM