I am working on an iPhone application in which I need to download 100-200 images from a server using the image URL in a for loop. Example:
NSOperationQueue *queue = [NSOperationQueue new]; NSInvocationOperation *operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(downloadImages:) object:arrayTemp]; [queue addOperation:operation]; [operation release]; [queue release]; -(void)downloadImages{ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; UIImage *image; for (int i=0; i < [self.ImagesRecords count]; i++) { ImageData *data =(ImageData*) [self.ImagesRecords objectAtIndex:i]; NSString *strName = [NSString stringWithFormat:@"image_%@",data.ID]; image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[@"http://abc.com" stringByAppendingString:data.PhotoPath]]]]; if (image!=nil) { [self saveImage:image withName:strName]; } } image = nil; [pool release]; }
His work is beautiful and gives me an image.
My questions:
- How can I get multiple images in one XML call? Is it possible?
- What is the way to upload files? Provide a snippet of code.
- Several times I found that my application got stuck for a while when this image is loading. What is the reason for this?
source share