应该如何处理beginbackgroundtaskwithexpirationhandler:处理已经在进行中的NSUrlConnection? [英] How should beginbackgroundtaskwithexpirationhandler: be dealt with for an NSUrlConnection that is already in progress?

查看:101
本文介绍了应该如何处理beginbackgroundtaskwithexpirationhandler:处理已经在进行中的NSUrlConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果应用程序使用NSURLConnection在应用程序位于前台时开始下载,但随后应用程序在数据下载完成之前移至后台,则应用程序应如何使用beginbackgroundtaskwithexpirationhandler:对于此已存在的连接?

If the application uses NSURLConnection to start a download while the app is in the foreground, but then the app moves to the background before the data has finished downloaded, then how should the app make use of beginbackgroundtaskwithexpirationhandler: for this already existing connection?

有很多可用的参考资料显示如何使用NSURLConnection initWithRequest:在应用程序移入后台后开始下载,没有任何显示如何处理NSURLConnection initWithRequest:已经在应用程序处于前台时被调用但在应用程序进入后台时尚未完成以及如何继续的情况。

There's plenty of reference material available showing how to use NSURLConnection initWithRequest: to START a download AFTER the app has moved into the background, there is nothing showing how to deal with the situation where NSURLConnection initWithRequest: has already been called while the app is in the foreground but hasn't yet finished when the app moves into the background and how to continue.

TIA

推荐答案

您需要将其作为后台任务启动,即使该任务在前景开头。请查看此Apple文档中超出基础知识部分: https://developer.apple.com/library/ios/ipad/#technotes/tn2277/_index.html

You need to start it as a background task for task that you wish to continue in background even if that task is in foreground beginning with. Check out the section "beyond the basics" in this Apple doc: https://developer.apple.com/library/ios/ipad/#technotes/tn2277/_index.html

这篇关于应该如何处理beginbackgroundtaskwithexpirationhandler:处理已经在进行中的NSUrlConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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