Annullamento dei download con AFNetworking con CancellLallHTTPoperationswithMetEthod non funziona

StackOverflow https://stackoverflow.com//questions/10676897

Domanda

Sono bloccato che annulla download con afnetworking.Nella mia app, l'utente può attivare i download singoli cinematografici in questo modo:

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];
.

funziona bene.Ma come posso forzare un download per essere fermato?Ho letto di usare questo metodo:

cancelAllHTTPOperationsWithMethod
.

Se lo uso in questo modo, non fa niente:

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

Quale sarebbe il modo corretto per annullare il download?

Molte grazie in anticipo.

È stato utile?

Soluzione

AFHTTPRequestOperation è una sottoclasse di NSOperation, che ha un metodo -cancel.Usalo.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top