使用AFAetworking取消下载使用cancelAllHTTPOperationsWithMethod不起作用

bra*_*ray 2 iphone networking ios afnetworking

我无法通过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];
Run Code Online (Sandbox Code Playgroud)

这很好.但是如何强制下载停止?我读到了使用这种方法:

cancelAllHTTPOperationsWithMethod
Run Code Online (Sandbox Code Playgroud)

如果我这样使用它,它什么都不做:

AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:@"http://www.xyz/mymovie.mp4"];
[client cancelAllHTTPOperationsWithMethod:nil path:@"http://www.xyz/mymovie.mp4"];
Run Code Online (Sandbox Code Playgroud)

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

提前谢谢了.

mat*_*ttt 5

AFHTTPRequestOperation是一个子类NSOperation,有一个-cancel方法.用那个.