CancelAllHttpOperationSwithMethod와 함께 Afnetworking을 사용하여 다운로드 취소 작동하지 않습니다
-
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