I can download a single URL but if I try to "harvest" all urls out of that page and then download all of those, I never receive a CALLBACK for those called from my scanResults method below.
I receive a callback from the first (i.e. main URL) and the page is downloaded fine. I pass the filename to a seperate thread (scanResults) which opens the file and tries to download every url in that page. Again, I don't get a callback. Any ideas why??? THANKS.
- (void)downloadDidFinish:(NSURLDownload *)download { NSEnumerator *e; id object;
e=[urlArray objectEnumerator]; while ( object = [e nextObject] ) { if([object objectForKey:@"nsurldownload"] == download) { [NSThread detachNewThreadSelector:@selector(scanResults:) toTarget:self withObject:[object objectForKey:@"filename"]]; } } [download release]; } -(IBAction)scanResults:(id)sender { NSString *aRow; NSString *fileContents; NSArray *rowArray; NSArray *rowComponents; NSString *pageFile;
fileContents = [NSString stringWithContentsOfFile:sender]; rowArray = [fileContents componentsSeparatedByString:@"\n"]; int i,rowCount = [rowArray count]; for(i=0;i<rowCount;i++) { aRow = [rowArray objectAtIndex:i]; rowComponents = [aRow componentsSeparatedByString:@"http://"];
NSString *tmpString = [NSString stringWithString:@"\""]; NSArray *parseArray = [[rowComponents objectAtIndex:1] componentsSeparatedByString:tmpString];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:[parseArray objectAtIndex:0]] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:10.0]; NSURLDownload *theDownload=[[NSURLDownload alloc] initWithRequest:theRequest delegate:self]; if (theDownload) { pageFile = [[NSString alloc] initWithFormat:@"%@/%f",ironWebDir,[[NSDate date] timeIntervalSinceReferenceDate]]; [theDownload setDestination:pageFile allowOverwrite:YES]; NSMutableDictionary *record = [NSMutableDictionary dictionary]; [record setObject:theDownload forKey:@"nsurldownload"]; [record setObject:[parseArray objectAtIndex:0] forKey:@"url"]; [record setObject:pageFile forKey:@"filename"]; [urlArray addObject:record]; [downloadHistoryTV reloadData]; } } }
|