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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T03:00:50+00:00 2026-06-02T03:00:50+00:00

I have some difficulties to set up the correct configuration relative to sendAsynchronousRequest:queue:completionHandler: method

  • 0

I have some difficulties to set up the correct configuration relative to sendAsynchronousRequest:queue:completionHandler: method (NSURLConnection class).

My scenario is the following:

I set up a singleton class that manages different NSURLConnections. This singleton istance has a NSOperation Queue (called downloadQueue) that makes a request to a web server and retrieves a string path (1).
Once done, the path is used to download a file within a web server (2). Finally, when the file has been correctly downloaded, I need to update the UI (3).

I figured out only the first request: the one through which I’m able to download the path. Could you suggest me a way to perform the other two steps?

Few questions here:

  • the download queue (downloadQueue) is not the main one, is it possible to open a new NSURLConnection in that queue? In other words, is it correct? (See comments in code snippets)

  • if the previous question is correct, how can I grab the main queue and update the UI?

Here the code snippet I use to perform the first step where downloadQueue is an instance variable that can be obtain through accessor mehods (@property/@synthesized);

// initializing the queue...
downloadQueue = [[NSOperation alloc] init];    

// other code here...
[NSURLConnection sendAsynchronousRequest:urlRequest queue:[self downloadQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {

    if([data length] > 0 && error == nil) {

        // here the path (1)
        // how to perform a second connection?
        // what type of queue do I have to use?              
    }
}];
  • 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-02T03:00:51+00:00Added an answer on June 2, 2026 at 3:00 am

    You’re on the right track for performing your first download.

    In the completion handler block after the first download, you’re computing the URL that you’ll need for a second download, right? Then you can perform that second download the same way: call +[NSURLConnection sendAsynchronousRequest:...] again with the new URL and the same queue. You can do this within the completion block for the first download.

    To update the UI after the second download is done, switch to the main queue within the completion block for that download. You can do this with dispatch_async() or dispatch_sync() (in this case it doesn’t matter which because you don’t have further work to do on the download queue) and dispatch_get_main_queue(), or with -[NSOperationQueue addOperationWithBlock:] and +[NSOperationQueue mainQueue].

    Your code should look something like this:

    // init download queue
    downloadQueue = [[NSOperationQueue alloc] init];    
    
    // (1) first download to determine URL for second
    [NSURLConnection sendAsynchronousRequest:urlRequest queue:[self downloadQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
        if([data length] > 0 && error == nil) {
            // set newURLRequest to something you get from the data, then...
            // (2) second download
            [NSURLConnection sendAsynchronousRequest:newURLRequest queue:[self downloadQueue] completionHandler:^(NSURLResponse *newResponse, NSData *newData, NSError *newError) {
                if([newData length] > 0 && newError == nil) {
                    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                        // (3) update UI
                    }];
                }
            }];
        }
    }];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some difficulties for using Ruby block, passing in a method. As in
I have the following setup in my application and I'm having some difficulties passing
I have some difficulties understanding how the access method Do not move cursor automatically
I have some difficulties in my project. I got the RGB values from a
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
I have had some difficulties in using extended classes in rails, in particular extending
I have a set of divs with the same class. I need to give
I am developing a GUI application in Qt, and I have some difficulties embedding
i have some understanding difficulties. i have some checkboxes in html like this: <input
I have some difficulties understanding how Boost.MultiIndex is implemented. Lets say I have the

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.