gpt4 book ai didi

iphone - 如何取消 iOS 后台的所有 NSURLConnections

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:18:28 25 4
gpt4 key购买 nike

我正在使用 NSURLCOnnections 下载一些图像(大约 200-300 个缩略图)。我有这些图片的 url 数组。连接开始下载这些图像。但在某些情况下我想取消所有这些下载。怎么可能。我可以取消所有这些 NSURLConnections 吗?

最佳答案

创建 NSOperationQueue 并通过此队列使用 NSURLConnection 会更好。

例如:

NSOperationQueue *queue = [NSOperationQueue new];
NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(sendRequest)];


- (void) sendRequest {
NSURL *url = [NSURL URLWithString:@"http://www.google.com"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSURLConnection *theConnection = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];
...
}

NSOperationQueue 有方法 cancelAllOperations

关于iphone - 如何取消 iOS 后台的所有 NSURLConnections,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15018726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com