我被AFnetworking取消了下载。在我的应用程序中,用户可以通过这种方式触发单电影下载:

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject)
                                         {
                                             //do success stuff

                                         }
                                 failure:^(AFHTTPRequestOperation *operation, NSError *error)
                                         {
                                             NSLog(@"Error downloadMovie: %@", error);
                                         }];
[operation start];
.

工作正常。但是如何强迫下载停止?我读过关于使用此方法的读取:

cancelAllHTTPOperationsWithMethod
.

如果我以这种方式使用它,它就不做任何事情:

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:@"http://www.xyz/mymovie.mp4"];
[client cancelAllHTTPOperationsWithMethod:nil path:@"http://www.xyz/mymovie.mp4"];
.

取消下载的正确方法是什么?

非常感谢。

有帮助吗?

解决方案

AFHTTPRequestOperationNSOperation的子类,其具有-cancel方法。使用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top