Attempting to download multiple files from an XML feed. There are several Categories and each category has an unknown amount of images. I create a subdirectory for each category, no problem. When I try to download each file to the respective category, every file is written with the same data for every image there is in the feed.
I guess my question is how can I download 1 file at a time to the corresponding directory without overwriting all of the images with the same data?
-(void)parsingComplete:(XMLDataSource*)theParser
{
/* iterate through the Categories and create the
sub-directory if it does not exist
*/
for (int i = 0; i < [categories count]; i++)
{
NSString *cat = [NSString stringWithFormat:@"%@/%@",BASE_DIR,[[categories objectAtIndex:i] objectForKey:@"name"]];
NSString *catName = [[categories objectAtIndex:i] objectForKey:@"name"];
NSArray *catArray = [[categories objectAtIndex:i] objectForKey:@"images"];
/* create the sub-direcotry naming it the #category# key */
if (![FILEMANAGER fileExistsAtPath:cat]) {
[FILEMANAGER createDirectoryAtPath:cat withIntermediateDirectories:NO attributes:nil error:nil];
}
//NSLog(@"\n\nCategory: %@",cat);
for (int x = 0; x < [catArray count]; x++)
{
/* download each file to the corresponding category sub-directory */
fileOut = [NSString stringWithFormat:@"%@/%@_0%i.jpg",cat,catName,x];
NSURLRequest * imageRequest =
[NSURLRequest requestWithURL:[NSURL URLWithString:[[catArray objectAtIndex:x] objectForKey:@"imageUrl"]]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:30.0];
[[NSURLConnection alloc] initWithRequest:imageRequest delegate:self];
}
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[receivedData writeToFile:fileOut atomically:YES];
}