我想取消異步下載使用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委託錯誤也不會被調用