使用afnetworking与cancelallhttpoperationswithmethod取消下载不起作用
-
12-12-2019 - |
题
我被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"];
.
取消下载的正确方法是什么?
非常感谢。
解决方案
AFHTTPRequestOperation
是NSOperation
的子类,其具有-cancel
方法。使用。
不隶属于 StackOverflow