Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5989085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:03:03+00:00 2026-05-22T23:03:03+00:00

I have various image size files loaded on each URL and would like to

  • 0

I have various image size files loaded on each URL and would like to download the data at the same time without using multiple calls to each URL. I am trying to loop through the URL using a variable and storing the data. Is it the correct way of doing it ?

- (id)initWithFrame:(CGRect)frame {

self = [super initWithFrame:frame];
if (self) {
    // Initialization code.

    isImageRequested = NO;
}
return self;
}

-(BOOL) isImageRequested
{
   return isImageRequested;
}


-(void) startImageDownloading
{

if (!isImageRequested)
{
    isImageRequested = YES;

    for (int i = 1; i <= 7; i++) {

        NSLog(@"Inside for loop");
        URLString = [NSString stringWithFormat:@"http://www.abc.com/method=image&size=%d", i];  
        //NSLog(@"string : %d", URLString);
        self.responseData = [NSMutableData data];
        NSURLRequest *pServerRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]];
        self.serverConnection= [[[NSURLConnection alloc] 
                                 initWithRequest:pServerRequest delegate:self] autorelease];

              /*UPDATED*/
                    if (i == 1) {

            prefixString = @"image_124_";
        }

        if (i == 2) {

            prefixString = @"image_250_";
        }

        if (i == 3) {

            prefixString = @"image_500_";
        }

        if (i == 4) {

            prefixString = @"image_750_";
        }

        if (i == 5) {

            prefixString = @"image_1000_";
        }

        if (i == 6) {

            prefixString = @"image_1500_";
        }

        if (i == 7) {

            prefixString = @"image_2000_";
        }


    }
   }

}



 -(void)cancelConnectionRequest
  {
    if (isImageRequested && serverConnection != nil)
    {
    [self.serverConnection cancel];self.serverConnection = nil;
    [self removeActivityIndicator];
    [self deallocateResources];
    isImageRequested = NO;
   }

  }

  - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:           (NSURLAuthenticationChallenge *)challenge 
    {
      if ([challenge.protectionSpace.authenticationMethod  isEqualToString:NSURLAuthenticationMethodServerTrust])
{
    [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];
}
[challenge.sender continueWithoutCredentialForAuthenticationChallenge:challenge];
}


 -(void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *)   response 
   {
     [responseData setLength:0]; 

    }


 -(void) connection:(NSURLConnection *) connection didReceiveData:(NSData *) data 
  {
    [responseData appendData:data];

   }

   -(void) connection:(NSURLConnection *) connection didFailWithError:(NSError *) error 
    {
NSLog(@"Error occured while loading image : %@",error);
[self removeActivityIndicator];
[self deallocateResources];


UILabel *tempLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 150, 30)];
[tempLabel setBackgroundColor:[UIColor clearColor]];
[tempLabel setFont:[UIFont systemFontOfSize:11.0f]];
[tempLabel setCenter:CGPointMake(self.frame.size.width/2, self.frame.size.height/2)];
[tempLabel setText:@"Image not available."];
[self addSubview:tempLabel];
[tempLabel release];

 }


-(void) connectionDidFinishLoading:(NSURLConnection *) connection 
 {


UIImage *tempImage = [[UIImage alloc] initWithData:responseData];
NSData *imageData = UIImagePNGRepresentation([UIImage imageWithData:responseData]);

self.image = tempImage;

      /*UPDATED*/
     PhotoViewController *photoMap = [[PhotoViewController alloc] init] ;


 [photoMap saveTilesOfSize:(CGSize){500,500} forImage:tempImage toDirectory:directoryPath usingPrefix:prefixString]; 
[tempImage release];


}

   -(void) deallocateResources
  {

if (serverConnection != nil) 
{
    [serverConnection release];
    serverConnection = nil;
}
if (responseData != nil)
{
    [responseData release];
    responseData = nil;
     }

   }


 - (void)dealloc {
    [super dealloc];
[responseData release];
[serverConnection release];
 }


 @end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T23:03:04+00:00Added an answer on May 22, 2026 at 11:03 pm

    How you get your photos depends on what the server you connect to allows.

    It could have a specific URL where you can download a bunch of photos, or you could be forced doing it like you are doing now. Which is fully correct as an approach if the server does not allow to do anything fancier.

    So, it depends on the API of your service.

    On the other hand, if you don’t want to initiate multiple request at the same time, you could use an NSOperationQueue to serialize you network operations.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have a webapp where people can upload various image file types and on
I have a requirement to save an image file in various formats. The list
This is often situation, but here is latest example: Companies have various contact data
We have to compress a ton o' (monochrome) image data and move it quickly.
I need to calculate an approximate image size in inches assuming 300dpi. I have
I have a panorama application with a backgrond image if 800x1000 in size. I
I have a PHP image upload system which allows a user to upload various
I have the following code. It's used to combine various image attachments (and pdfs)
We have various php projects developed on windows (xampp) that need to be deployed
We have various servers that have many directories shared. It's easy enough to look

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.