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 8334159
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T03:15:18+00:00 2026-06-09T03:15:18+00:00

I just started using AFNetworking and so far it worked fine for just getting

  • 0

I just started using AFNetworking and so far it worked fine for just getting data from the web.

But now I have a list of files that need to be downloaded to the device

for(NSDictionary *issueDic in data)
{
    Issue *issue = [[Issue alloc] init];
    ...
    [self getOrDownloadCover:issue];
    ...
}

getOrDownloadCover:issue checks if a file already exists locally, if it does, it just saves that path, if it doesn’t, it downloads the file from a given url

- (void)getOrDownloadCover:(Issue *)issue
{
    NSLog(@"issue.thumb: %@", issue.thumb);

    NSString *coverName = [issue.thumb lastPathComponent];

    NSLog(@"coverName: %@", coverName);

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    __block NSString *filePath = [documentsDirectory stringByAppendingPathComponent:coverName];

    if([[NSFileManager defaultManager] fileExistsAtPath:filePath])
    {
        // Cover already exists
        issue.thumb_location = filePath;

        NSLog(@"issue.thumb_location: %@", filePath);
    }
    else 
    {
        NSLog(@"load thumb");

        // Download the cover
        NSURL *url = [NSURL URLWithString:issue.thumb];
        AFHTTPClient *httpClient = [[[AFHTTPClient alloc] initWithBaseURL:url] autorelease];
        NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:issue.thumb parameters:nil];

        AFHTTPRequestOperation *operation = [[[AFHTTPRequestOperation alloc] initWithRequest:request] autorelease];
        operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];

        [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        issue.thumb_location = filePath;

        NSLog(@"issue.thumb_location: %@", filePath);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"FAILED");
    }];
        [operation start];
    }
}

getOrDownloadCover:issue can be called 20 times in a row, so I would need to put all my requests into a queue, and once the queue is completed, it should still be able to save the path (or just send out a notification, since I already know what the path is)

Any suggestions for this?

  • 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-06-09T03:15:20+00:00Added an answer on June 9, 2026 at 3:15 am

    Add an NSOperationQueue to an object you can get the instance of at any point in your application, for example in your appDelegate. Then just add the AFHTTPRequestOperation to this queue like:

    [[(AppDelegate *) [UIApplication sharedApplication].delegate operartionQueue] addOperation:operation];
    

    Just handle the saving in the completion block, either call a methode from this block on the main thread or post a NSNotification.

    To call the main thread use GCD :

    dispatch_async(dispatch_get_main_queue(), ^{
        // Call any method from on the instance that created the operation here.
        [self updateGUI]; // example
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just started using Blueprint CSS and now playing with the grids but have a
I just started using Eclipse but already I have a small problem. At first
Just started using fadein/fadeout - it's functioning but with problems. I have a set
I just started using rapidxml. I 1st create an xml file to read from.
I just started using/learning Python and have some questions. I have a text file
I just started using virtualenv, and it was working normally until yesterday. Now, and
I just started using a javascript engine from Microsoft(of IE9?) for developing both desktop
Just started using the Ace editor (http://ace.ajax.org) and although it works fine on a
I´ve just started using ASIHTTPRequest for iOs and I have a small issue with
I just started using gApps scripts and I have run into two problems with

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.