AFNetworking 2和后台任务 [英] AFNetworking 2 and background tasks

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

问题描述

由于新的iOS7 NSURLSession后台请求,我对AFNetworking 2和后台下载/上传有疑问



这是由我的自动处理的吗AFHTTPRequestOperationManager ?它会自动将我的请求的会话设置为后台模式吗?
我看到了 AFURLSessionManager 有一个 setDidFinishEventsForBackgroundURLSessionBlock 方法,但是我想知道是否一切都是自动的吗?



如果我的应用程序被杀死或暂停,请求会继续吗?重新启动我的应用程序后如何获得回调?



非常感谢您的帮助!

解决方案

AFHTTPRequestOperationManager 使用旧的 NSURLConnection ,因此不利于后台下载。 / p>

AFURLSessionManager 在引擎盖下使用 NSURLSession 这样。我认为您仍然需要适当地配置 NSURLSession



NSURLSession类在应用程序处于运行状态时支持后台传输后台传输仅由使用后台会话配置对象创建的会话提供(由对backgroundSessionConfiguration的调用返回)。



建议阅读: URL加载系统


I have a question about AFNetworking 2 and background downloads/uploads thanks to the new iOS7 NSURLSession background requests

Is this automatically handled by my AFHTTPRequestOperationManager ? Does it automatically set my requests'session to background mode? I saw that the AFURLSessionManager Has a setDidFinishEventsForBackgroundURLSessionBlock Method but I wonder if everything is automatic?

If my app is killed or suspended, will requests keep on going? How can I get a callback when my app is relaunched?

Thanks a lot for your help!

解决方案

AFHTTPRequestOperationManager uses the old NSURLConnection so that doesn't facilitate background downloading.

AFURLSessionManager uses NSURLSession under the hood so that does. I think you still need to configure the NSURLSession appropriately.

"The NSURLSession class supports background transfers while your app is suspended. Background transfers are provided only by sessions created using a background session configuration object (as returned by a call to backgroundSessionConfiguration:)."

Suggested reading:URL Loading System

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

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