2011-09-30 67 views
0

我想取消異步下載使用ASIHTTPRequest沒有喜悅。我正在將視頻下載到ViewController外觀的磁盤上。我想要的是,當用戶點擊關閉關閉視圖控制器我想取消下載。這裏是我的代碼至今:ASIHTTPRequest異步下載沒有取消

發出請求:

-(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]; 
} 

取消下載:

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


[ashiRequest clearDelegatesAndCancel]; 


[self dismissModalViewControllerAnimated:YES]; 
} 

一切工作,在下載罰款和電影播放正常,但當我關閉視圖控制器時,請求不會被取消,我的文件仍在下載(網絡活動指示器在狀態欄上旋轉,即使ASIHTTP委託錯誤也不會被調用

回答

0

嘗試使用

ashiRequest.delegate = nil; 
[ashiRequest cancel]; 

這應該有效。

0

我想通了什麼是錯的。我正在使用Reachability來調用我的retrieveLatestFileMethod。如果在應用程序中僅使用Reachability一次,可能來自代理,那很好。但我有一些它的實例,所以它保持調用相同的功能和下載。