0

以下の関数はサーバーからコンテンツをダウンロードしておらず、ASIHTTPRequestErrorDomain Code =4"リクエストはキャンセルされました。

この関数はviewdidloadから呼び出されますが、同じURLが正常に機能しており、-(void)downLoad:(id)sender event:(id)event関数ではコンテンツを正常にダウンロードしていますが、-(void)startDownload関数ではダウンロードしていません。 。

私の関数の問題/間違ったことを教えてください(-(void)startDownload)

以下の機能は正常に動作しています

-(void)downLoad:(id)sender event:(id)event{

self.tblViewDownload.userInteractionEnabled = NO;

IsRequestCompleted = NO;

CGPoint touchPosition = [[[event allTouches] anyObject] locationInView:self.tblViewDownload];
NSIndexPath *indexPath = [self.tblViewDownload indexPathForRowAtPoint:touchPosition];
UITableViewCell *Cell = [self.tblViewDownload cellForRowAtIndexPath:indexPath];

progress = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
progress.frame = CGRectMake(65, 55, 210, 25);
progress.progress = 0.0;
[Cell.contentView addSubview:progress];

UIButton* button = (UIButton*)sender;
button.hidden=YES;

if(!self.networkQueue)
    self.networkQueue = [[[ASINetworkQueue alloc] init] autorelease];

[self.networkQueue cancelAllOperations];
[self.networkQueue setQueueDidFinishSelector:@selector(queueCompleted:)];
[self.networkQueue setShowAccurateProgress:YES];
[self.networkQueue setDownloadProgressDelegate:progress];

[self.networkQueue setDelegate:self];

NSDictionary *aDict =[self.myUrlArray objectAtIndex:[indexPath row]];
NSString *aImgUrl = [aDict objectForKey:@"IMG_URL"];
NSString *aVideoUrl = [aDict objectForKey:@"VIDEO_URL"];
NSString *aAudioUrl = [aDict objectForKey:@"AUDIO_URL"];

NSArray *aPoemArrayUrls = [NSArray arrayWithObjects:aImgUrl,aVideoUrl,aAudioUrl,nil];

for(NSString* urlString in aPoemArrayUrls)
{
    NSURL *url = [NSURL URLWithString:urlString];
    ASIHTTPRequest *downloadAFileRequest = [[ASIHTTPRequest requestWithURL:url]retain];
    NSString *Filename = [urlString lastPathComponent];
    NSLog(@"%@ filename",Filename);
    [downloadAFileRequest setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
    [downloadAFileRequest setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:Filename]];
    [downloadAFileRequest setShouldContinueWhenAppEntersBackground:YES];
    [downloadAFileRequest setDelegate:self];
    [downloadAFileRequest setDidFinishSelector:@selector(requestDone:)];
    [downloadAFileRequest setDidFailSelector:@selector(requestWentWrong:)];
    [downloadAFileRequest setShowAccurateProgress:YES];

    [self.networkQueue addOperation:downloadAFileRequest];
    //----
}

[self.networkQueue go];

}

以下の関数は機能せず、ASIHTTPRequestErrorDomain Code=4を返します"リクエストはキャンセルされました

-(void)startDownload{

if([self.myUrlArray count] > 0 ){

int count = [self.myUrlArray count];

int i = count - count;

NSLog(@"%d iiiiii",i);

NSIndexPath *myIP = [NSIndexPath indexPathForRow:i inSection:0];

UITableViewCell *Cell = [self.tblViewDownload cellForRowAtIndexPath:myIP];

progress = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleBar];
progress.frame = CGRectMake(65, 55, 210, 25);
progress.progress = 0.0;
progress.backgroundColor = [UIColor redColor];
[Cell.contentView addSubview:progress];

  if(!self.networkQueue)
      self.networkQueue = [[[ASINetworkQueue alloc] init] autorelease];

  [self.networkQueue cancelAllOperations];
  [self.networkQueue setQueueDidFinishSelector:@selector(queueCompleted:)];
  [self.networkQueue setShowAccurateProgress:YES];
  [self.networkQueue setDownloadProgressDelegate:progress];

  [self.networkQueue setDelegate:self];

  NSDictionary *aDict =[self.myUrlArray objectAtIndex:[myIP row]];
  NSString *aImgUrl = [aDict objectForKey:@"IMG_URL"];
  NSString *aVideoUrl = [aDict objectForKey:@"VIDEO_URL"];
  NSString *aAudioUrl = [aDict objectForKey:@"AUDIO_URL"];

  NSArray *aPoemArrayUrls = [NSArray arrayWithObjects:aImgUrl,aVideoUrl,aAudioUrl,nil];

  for(NSString* urlString in aPoemArrayUrls)
  {
      NSURL *url = [NSURL URLWithString:urlString];
      ASIHTTPRequest *downloadAFileRequest = [[ASIHTTPRequest requestWithURL:url]retain];
      NSString *Filename = [urlString lastPathComponent];
      NSLog(@"%@ filename",Filename);
      [downloadAFileRequest setUserInfo:[NSDictionary dictionaryWithObject:@"request1" forKey:@"name"]];
      [downloadAFileRequest setDownloadDestinationPath:[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"] stringByAppendingPathComponent:Filename]];
      [downloadAFileRequest setShouldContinueWhenAppEntersBackground:YES];
      [downloadAFileRequest setDelegate:self];
      [downloadAFileRequest setDidFinishSelector:@selector(requestDone:)];
      [downloadAFileRequest setDidFailSelector:@selector(requestWentWrong:)];
      [downloadAFileRequest setShowAccurateProgress:YES];

      [self.networkQueue addOperation:downloadAFileRequest];
  }

  [self.networkQueue go];


}
}
4

1 に答える 1

2

IsRequestCompleted = NO;2番目の関数で設定するのを忘れたと思います。また、なぜcancelAllOperationsを送信するのですか?それが問題になる可能性が高いです。

self.networkQueueまた、毎回自動リリースして再初期化する必要はありません。クラスに一度設定して、でリリースするだけ-deallocです。

于 2012-08-08T13:56:36.507 に答える