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

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

问题描述

有什么办法可以例如说:

Is there any way I can for example say:

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

当然,如果这些请求(尤其是在图像下载的情况下)只会在稍后调用相同的 URL 时暂停,但是...我至少需要能够在全局范围内取消所有请求等级.一些建议?

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.SessionManager.default.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天全站免登陆