cancelar descargas usando AFNetworking con cancelAllHTTPOperationsWithMethod no funciona
-
12-12-2019 - |
Pregunta
Estoy atascado al cancelar descargas con AFNetworking.En mi aplicación, el usuario puede activar descargas de películas individuales de esta manera:
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];
Eso funciona bien.Pero, ¿cómo puedo forzar la detención de una descarga?Leí sobre el uso de este método:
cancelAllHTTPOperationsWithMethod
Si lo uso de esta manera no hace nada:
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:@"http://www.xyz/mymovie.mp4"];
[client cancelAllHTTPOperationsWithMethod:nil path:@"http://www.xyz/mymovie.mp4"];
¿Cuál sería la forma correcta de cancelar la descarga?
Muchas gracias de antemano.
Solución
AFHTTPRequestOperation
es una subclase de NSOperation
, que tiene un -cancel
método.Usa eso.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow