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)
{
float difference = [[NSDate date] timeIntervalSinceReferenceDate] - [[object objectForKey:@"startTime"] timeIntervalSinceReferenceDate];
[object setObject:[NSNumber numberWithFloat:difference] forKey:@"latency"];
[downloadHistoryTV reloadData];
if([harvestSwitch state] == NSOnState)
{
if(currentPageCount < totalPagesPermitted)
[NSThread detachNewThreadSelector:@selector(scanResults:) toTarget:self withObject:[object objectForKey:@"filename"]];
}
}
}
[download release];
}
-(IBAction)scanResults:(id)sender
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
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://"];
if([rowComponents count] < 2)
continue;
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:[NSDate date] forKey:@"startTime"];
[record setObject:pageFile forKey:@"filename"];
[urlArray addObject:record];
[downloadHistoryTV reloadData];
}
}
[pool release];
}