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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:58:36+00:00 2026-06-10T14:58:36+00:00

Using AFNetworking, I need to download ~100 images in the background and store them

  • 0

Using AFNetworking, I need to download ~100 images in the background and store them to disk while ensuring any other network connectivity in my app takes precedence.

~~~~~~~

I’ve got an application that has 4 tabs. Each tab basically does the same thing: Pulls down a JSON response from a server, and displays a thumbnail grid of images, pulling down each image on demand (using AF’s ImageView category). Tapping on a thumbnail takes you to a detail view controller where you see a larger image. The response and images are different for each tab.

There’s a new requirement to fetch all of the images for the 4th tab ahead of time, so that theoretically by the time the user taps on the 4th tab, the JSON data and images are being read from disk.

I’ve got this working more or less right now, with the 4th tab pre-fetching and saving to disk being performed on a background thread so the main thread doesn’t lock up. However, the network requests being kicked off when a user is on the 1st, 2nd or 3rd tab are being blocked by the pre-fetching network requests.

I’m using AFNetworking, and here is the code I’m using when Tab 1, 2 or 3 loads:

// this network request ends up getting blocked by the network request that
// is fired upon the application becoming active
- (void)getAllObjectDataWithBlock:(AFCompletionBlockWrapper)block
{
    [[[MyAPIClient] sharedClient] getPath:@"" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        block(operation, responseObject, nil);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        block(operation, nil, error);
    }];
}

And here is the code I’m using when my application becomes active, to pre-fetch content for the 4th tab:

// this network request runs in the background, but still blocks requests
// that should have a higher priority
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        NSOperationQueue *imageQueue = [[NSOperationQueue alloc] init];
        [imageQueue setMaxConcurrentOperationCount:8];

        for (NSString *imageURL in self.images) {                    
            NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL imageURL]];

            AFImageRequestOperation *operation = [[AFImageRequestOperation alloc] initWithRequest:request];
            [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
                NSLog(@"success");
            } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                NSLog(@"fail");
            }];

            [imageQueue addOperation:smallOperation];
        }
    });
}

How can I structure things so any network requests kicked off from the main thread interrupt those that were kicked off in the background thread?

  • 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-10T14:58:38+00:00Added an answer on June 10, 2026 at 2:58 pm

    I don’t know that you can easily interrupt running operations, unless you want to send them a cancel–but you’d have to look at whether AFImageRequestOperation pays attention to isCancelled.

    Have you tried using setQueuePriority? You could start all the pre-fetching requests with a low priority, then add current tab requests with a higher priority. I believe running operations would complete, but once they complete, your higher-priority operations would get scheduled ahead of queued low-priority ones.

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

Sidebar

Related Questions

I'm using AFNetworking to pull images from a URL, resize, store to disk and
I'm using AFNetworking and like it very much. I need to get JSON data
I've encountered a problem using AFNetworking to download files from a Rackspace repository. Basically
I am attempting to use AFNetworking with an XML-RPC based API while using GDataXML
I'm using AFNetworking for my iOs app. I need to implement a search-suggest like
I'm using AFNetworking as a network layer for my iPhone app which connects to
I am using the AFNetworking library. I can't figure out how to download a
I'm trying to download multiple files using the AFNetworking classes. I'm a complete newbie
I'm using AFNetworking for asynchronous calls to a web service. Some of these calls
I'm using AFNetworking to upload files to a web service using a multi-part POST.

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.