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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:50:50+00:00 2026-06-17T11:50:50+00:00

I am using NSURLConnection to load data from a response. It works as it

  • 0

I am using NSURLConnection to load data from a response. It works as it should, the delegate method connectionDidFinishLoading has the connection instance with the data I need. The problem is that I want to pass some information along with the request so that I can get it when the connection finishes loading:

  1. User wants to share the content of a URL via (Facebook, Twitter,
    C, D).
  2. NSURLConnection is used to get the content of the URL
  3. Once I have the content, I use the SL framework
    SLComposeViewController:composeViewControllerForServiceType and need
    to give it the service type
  4. At this point I don’t know what service the user selected in step 1. I’d like to send that with the NSURLConnection.

Can I extend NSURLConnection with a property for this? That seems very heavy-handed. There must be a “right way” to do this.

Many Thanks

  • 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-17T11:50:51+00:00Added an answer on June 17, 2026 at 11:50 am

    Assuming you don’t need the delegate-based version of the NSURLConnection process for some other reason, this is a good use case for the block-based version:

    - (void)shareContentAtURL:(NSURL *)shareURL viaService:(NSString *)service
    {
        NSURLRequest *urlRequest = [NSURLRequest requestWithURL:shareURL];
        NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    
        [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
        {
            if ([data length] == 0 && error == nil) {
                // handle empty response
            } else if (error != nil) {
                // handle error
            } else {
                // back to the main thread for UI stuff
                [[NSOperationQueue mainQueue] addOperationWithBlock:^{
                    // do whatever you do to get something you want to post from the url content
                    NSString *postText = [self postTextFromData:data]; 
    
                    // present the compose view
                    SLComposeViewController *vc = [SLComposeViewController composeViewControllerForServiceType:service];
                    [vc setInitialText:postText];
                    [self presentViewController:vc animated:YES]; 
                }];
            }   
        }];
    
    }
    

    Since blocks can capture variables from their surrounding scope, you can just use whatever context you already had for the user’s choice of service inside the NSURLConnection‘s completion block.

    If you’re still wed to the delegate-based NSURLConnection API for whatever reason, you can always use an ivar or some other piece of state attached to whatever object is handling this process: set self.serviceType or some such when the user chooses a service, then refer back to it once you get your content from the NSURLConnectionDelegate methods and are ready to show a compose view.

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

Sidebar

Related Questions

I'm using NSURLConnection to pull data from a webpage. I'm looking to find a
I'm using NSURLConnection with sendAsynchronousRequest method (and handing the data in block). Using above
I am downloading images using the NSURLConnection sendSynchronousRequest method and that works fine. However,
I have table view to load data from an API call. I am using:
how can i make complete data when using NSURLConnection? - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
I load data from Internet, and parse it using DDXML parser in another thread.
iam currently using NSURLConnection class to hit my server and get some data from
I have been using NSURLConnection's sendAsynchronousRequest:queue:completionHandler: method which is great. But, I now need
I am using NSURLConnection to send same data ( NSString ) to the server
I m making call to server using NSURLConnection for iPhone & receiving the response

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.