Das Abbrechen von Downloads über AFNetworking mit cancelAllHTTPOperationsWithMethod funktioniert nicht
-
12-12-2019 - |
Frage
Ich stecke beim Abbrechen von Downloads mit AFNetworking fest.In meiner App kann der Benutzer einzelne Filmdownloads folgendermaßen auslösen:
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];
Das funktioniert gut.Aber wie kann ich das Stoppen eines Downloads erzwingen?Ich habe über die Verwendung dieser Methode gelesen:
cancelAllHTTPOperationsWithMethod
Wenn ich es so verwende, macht es nichts:
AFHTTPClient *client = [[AFHTTPClient alloc] initWithBaseURL:@"http://www.xyz/mymovie.mp4"];
[client cancelAllHTTPOperationsWithMethod:nil path:@"http://www.xyz/mymovie.mp4"];
Was wäre der richtige Weg, um den Download abzubrechen?
Vielen Dank im Voraus.
Lösung
AFHTTPRequestOperation
ist eine Unterklasse von NSOperation
, das eine hat -cancel
Methode.Verwende das.
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow