2011-09-30 3 views
0

ASIHTTPRequest를 사용하여 비동기 다운로드를 취소하려고 시도하고 있습니다. ViewController의 모양으로 디스크에 동영상을 다운로드합니다. 원하는 것은 사용자가 닫기를 클릭하여보기 컨트롤러를 닫고 다운로드를 취소하려는 경우입니다.ASIHTTPRequest 비동기 다운로드 취소하지 않습니다

요청 만들기 : 모든 것이 작동

- (IBAction)closeDocDisplay:(id)sender { 
// Cancels an asynchronous request 


[ashiRequest clearDelegatesAndCancel]; 


[self dismissModalViewControllerAnimated:YES]; 
} 

, 다운로드가 미세하고 영화가 제대로 재생하지만 :

-(void)retrieveLatestFile{ 

NSURL *url = [NSURL URLWithString:[appDelegate.urlToLoad stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

ashiRequest = [[ASIHTTPRequest requestWithURL:url] retain]; 
[ashiRequest setUsername:@"Appidae"]; 
[ashiRequest setPassword:@"Dubstance1"]; 
[ashiRequest setDelegate:self]; 
[ashiRequest startAsynchronous]; 
[ashiRequest setDownloadProgressDelegate:progressView]; 
NSLog(@"Value: %f", [progressView progress]); 
if ([progressView progress]==1) { 
    [self hideInfoPane]; 
} 
//NSLog(@"Max: %f, Value: %f", [myProgressIndicator maxValue],[myProgressIndicator doubleValue]); 
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 

NSString *documentsDirectory = [paths objectAtIndex:0]; 

NSString *tempPath = [NSString stringWithFormat:@"%@/download/%@/%@", documentsDirectory, appDelegate.languageFolder,appDelegate.filename]; 


NSLog(@"Path: %@", tempPath); 

[ashiRequest setDownloadDestinationPath:tempPath]; 
} 

가 다운로드 취소를 여기 코드는 내가 지금까지 가지고있다 View Controller를 닫을 때 요청이 취소되지 않고 파일이 여전히 다운로드 중입니다 (상태 표시 줄의 네트워크 활동 표시기가 회전 함). ASIHTTP 대리인 오류조차도 호출되지 않습니다.

답변

0

사용해보기

ashiRequest.delegate = nil; 
[ashiRequest cancel]; 

이렇게하면됩니다.

0

나는 무엇이 잘못되었는지 알아 냈습니다. Reachability를 사용하여 retrieveLatestFileMethod를 호출했습니다. Reachability가 앱에서 단 한 번만 사용되었거나 대리인이 사용한 것일 수도 있습니다. 하지만 몇 가지 사례가 있었기 때문에 동일한 기능과 다운로드를 요구했습니다.

관련 문제