iOS Alamofire停止所有请求 [英] iOS Alamofire stop all requests

查看:591
本文介绍了iOS Alamofire停止所有请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有什么办法可以说:

Alamofire.Manager.cancelAllRequests() Alamofire.Manager.sharedInstance.cancelAllRequests()

当然,如果这些请求特别是在图片下载只会暂停,因为我会收到相同的网址,但是......我至少需要能够在全球范围内取消所有请求。一些建议?

Of course it would be great if these requests especially in case of image download would only be paused for later when I'll cal the same URL but... I need at least to be able to cancel all requests at a global level. Some suggestions ?

在我的应用程序中,我有一个高于Alamofire.request(.Post ....)方式的包装器,所以我真的很感激我没有让我除了上面指定的方式之外,以另一种方式创建或与Manager类交互。

In my app I have a wrapper above the Alamofire.request(.Post....) way of doing things so I would really appreciate not making me create or interact with Manager class in another way besides that specified above.

推荐答案

您应该使用 NSURLSession 直接完成此任务的方法。

You should use the NSURLSession methods directly to accomplish this.

Alamofire.Manager.sharedInstance.session.invalidateAndCancel()

这将调用所有完成处理程序并取消错误。如果您需要能够恢复下载,那么您需要从请求中获取 resumeData (如果可用)。然后在准备好时使用简历数据恢复请求。

This will call all your completion handlers with cancellation errors. If you need to be able to resume downloads, then you'll need to grab the resumeData from the request if it is available. Then use the resume data to resume the request in place when you're ready.

这篇关于iOS Alamofire停止所有请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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