iOS中的NSURLConnection和多任务 [英] NSURLConnection and multitasking in iOS

查看:155
本文介绍了iOS中的NSURLConnection和多任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NSURLConnection 在iOS中异步下载资源。 (他们是大型的PDF文件,所以它需要一些时间慢的连接。)

I'm using NSURLConnection to download resources asynchronously in iOS. (They are large-ish PDF files, so it takes some time on a slow connection.)

现在我将我的应用程序从iOS 3更新到iOS 4。我的应用程序没有位置感知,voip和背景音乐,我想我需要做一些事情。

Now I'm updating my app from iOS 3 to iOS 4. As my app is none of location-aware, voip, and background music, I guess I need to do something.

我的问题是,那么,当前正在运行的 NSURLConnection 会发生什么?它是暂停和神奇地恢复,当应用程序回到前台,或者是它彻底杀了?如果是后者,什么是标准策略以后自动恢复它?是否有一个 NSURLConnection 的开源子类,它会自动执行?

My question is, then, what happens to the NSURLConnection currently running? Is it suspended and magically resumed when the app comes back to the foreground, or is it outright killed? If it is the latter, what is the standard strategy to resume it automatically later? Is there a open-source subclass of NSURLConnection which automatically does that?

推荐答案

p> NSURLConnection确实暂停,并在应用程序进入前台时再次启动。只要确保你杀死连接,如果应用程序从暂停到不运行像这样:

The NSURLConnection is indeed suspended and started again when the app enters the foreground. Just make sure you kill the connection if the app moves from suspended to not running like so:

- (void)applicationWillTerminate:(UIApplication *)application {
    if (self.downloadConnection != nil){
        [self.downloadConnection cancel];
    }
}

这篇关于iOS中的NSURLConnection和多任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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