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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:16:49+00:00 2026-05-23T16:16:49+00:00

I am working through through the basics of Objective-C, I’ve graduated past syntax but

  • 0

I am working through through the basics of Objective-C, I’ve graduated past syntax but I’m still not doing any ios specific stuff. Anyway, I’m trying to figure out http requests, and I can’t get an asynchronous post to work correctly.

I can go very basic (this works):

NSString *doc = [NSString stringWithContentsOfURL:url usedEncoding:&encoding error:&error];

NSLog(@"%@", doc);

And I can make a synchronous request (also works):

NSData *urlData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

NSString *doc = [[NSString alloc]initWithData:urlData encoding:NSASCIIStringEncoding];

But when I try this:

NSMutableURLRequest *urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
connection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self startImmediately:YES];

I can’t seem to get any of the connection methods to fire, such as didReceiveResponse or didReceiveData.

So here are my questions:

Will what I am trying to do work in a command-line obejctive c app?

-Does the delegate need to be “self”? Can I make a custom “delegate” class and add methods like:

-(void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
    NSLog(@"Data");
}

-If a custom delegate is possible, is it a good idea? Should I attach the above didReceiveData method to whatever class is performing the connection?

-Do I need to have some kind of task running continuously so my program doesn’t end before the response comes in?

-Am I barking up the wrong tree entirely? Can you set me straight?

Thanks in advance for your time.

  • 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-23T16:16:50+00:00Added an answer on May 23, 2026 at 4:16 pm

    NSURLConnection and NSURLRequest are both part of the Foundation framework, so you should be fine using them in your program. However, per the NSURLConnection documentation:

    For the connection to work correctly
    the calling thread’s run loop must be
    operating in the default run loop
    mode.

    You’ll want to read about NSRunLoop. Your command line app probably doesn’t have a run loop, which is why your async request isn’t doing what you expect.

    The delegate doesn’t have to be ‘self’ — it can be any object you like provided that object implements the appropriate delegate methods.

    Obviously, if the program exits before the connection completes its work, your program isn’t going to get the data it was looking for.

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

Sidebar

Related Questions

I'm still working my way through some pretty basic Actionscript programming (in Flex), and
Still working through JQuery to get data and repopulate portions of a page. Right
I'm working through the Erlang documentation, trying to understand the basics of setting up
Working through this for fun: http://www.diku.dk/hjemmesider/ansatte/torbenm/Basics/ Example calculation of nullable and first uses a
I'm completely new to Haskell. To grasp the basics I've started working through 'Learn
So, I'm working through a basic membership management admin panel but I can't quite
I'm working through the Stanford iPhone podcasts and have some basic questions. The first:
In working through the issues with another question, I've found text files with embedded
I'm working through Aaron Hillegass' book, specifically the lottery example. I had a question
I've recently been working through a large codebase, refactoring and generally improving design to

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.