如何在NSURLSession中查找和取消任务? [英] How to find and cancel a task in NSURLSession?

查看:119
本文介绍了如何在NSURLSession中查找和取消任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 NSURLSession 对象在我的应用程序中加载图像。这可能是同时加载几个图像。

I'm using an NSURLSession object to load images in my application. That could be loading several images simultaneously.

在某些时刻,我需要取消加载一个特定图像并继续加载其他图像。

In some moments I need to cancel the loading of one specific image and continue loading others.

你能建议正确的方法吗?

Could you suggest the correct way to do that?

推荐答案

要获取任务列表,您可以使用NSURLSession的方法

To get tasks list you can use NSURLSession's method

- (void)getTasksWithCompletionHandler:(void (^)(NSArray *dataTasks, NSArray *uploadTasks, NSArray *downloadTasks))completionHandler;




异步调用包含所有未完成数据的完成回调,
在会话中上传和下载任务。

Asynchronously calls a completion callback with all outstanding data, upload, and download tasks in a session.

然后检查 task.originalRequest.URL 返回任务以找到您要取消的任务。

Then check task.originalRequest.URL for returned tasks to find the one you want to cancel.

这篇关于如何在NSURLSession中查找和取消任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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