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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:58:32+00:00 2026-05-30T20:58:32+00:00

Hi guys this will be my first post and am pretty new to Objective-C

  • 0

Hi guys this will be my first post and am pretty new to Objective-C though not entirely new to coding. I’ve been doing a lot of reading and a lot of Googling and a lot of my answers have come from this site. So now I’m really stuck I figured it was about time I asked the experts.

I’m basically trying to get the raw HTML data from a given URL so that I can parse it for information. I have all the parsing sorted, and can retrieve the raw HTML however I’m struggling to understand how to get the program to stop while the data arrives from NSURLConnection so I can use it. Currently my program whizzes past the connection and the holding String gets left as empty, until shortly after when its filled by the request. I believe I need to use a “Syncronous” connection but this is frowned upon because it freezes the UI while its processing the request. I’m trying to call it like this ….

urlData = [getURLClass getURL: @"http://www.google.co.uk"];

Hoping to get raw HTML in to the String urlData so I can parse it.My current code from my class is below….

//Create the request
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:urlString]];

//Open NSURLConnection with 'request'
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc] init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
    //If we receive something
    if (data) {
        //Pass and decode to string
        receivedData = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
        NSLog(@"Received HTML: %@", receivedData); 
    }

    //Something went wrong
    else {
       // ToDO: Sort out any errors

    }
}];

return receivedData;

When this is run the log shows “Received HTML: nil” and the return value is also blank, but if I wait a moment then call the class again its been filled with data from the previous request. I did try another method which the data was retrieved in to

-(void) connectionDidFinishLoading

But this leaves me the problem that I cannot “return” the data from the Method that was called. As I said I’m very new to Objective-C. I’m aware there are discontinued wrappers like ASIHTTPRequest, but I’m sure there is a simpler answer to this than using someone else’s class. It will also help me to learn if I can find an answer, I simply need to get the program to wait while the data is received before the class return it. I may be trying to run before I can walk with Obj-C, but my program is useless unless I can interact with the web.

Thanks in advance.
Plasma

  • 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-30T20:58:33+00:00Added an answer on May 30, 2026 at 8:58 pm

    I wrote a class file for this type of situation.

    CAURLDownload.h:
    http://localhostr.com/file/vGtIIpO/CAURLDownload.h

    CAURLDownload.m:
    http://localhostr.com/file/TAieiAE/CAURLDownload.m

    Basically, you want to call
    [CAURLDownload downloadURL:URL target:self selector:@selector(finishedSelector: connection:) failSelector:@selector(failureSelector:) userInfo:userInfo];

    URL is an NSURL and userInfo is an NSDictionary.

    Basically, you call that method with the appropriate parameters and execute your parsing in finishedSelector. Example:

    [CAURLDownload downloadURL:[NSURL URLWithString:@"http://couleeapps.hostei.com"]
                        target:self
                      selector:@selector(downloadFinished:connection:)
                  failSelector:@selector(downloadFailed:)
                      userInfo:nil];
    

    And for the methods:

    - (void)downloadFinished:(NSData *)recievedData conneciton:(CAURLDownload *)connection {
        //Parse recievedData
        NSString *recievedString = [[[NSString alloc] initWithData:recievedData] autorelease];
        //Etc.
    }
    
    - (void)downloadFailed:(CAURLDownload *)connection {
        NSLog(@"Download Failed!");
        //Do something
    }
    

    This has both the upsides of not locking the UI, being memory-friendly, and callable without a pointer required (singleton).

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

Sidebar

Related Questions

This will be simple for you guys: var uri = new Uri(pack://application:,,,/LiftExperiment;component/pics/outside/elevator.jpg); imageBitmap =
As outlined by this guys post, blocking IP's via PHP is pretty easy. However,
Forgive me guys, new to Ruby, actually this is the first lang I have
First post, but I've been lurking around this site for a long while now,
Hi Guys new to this site but a big fan. Right the problem. It's
Hello guys I am new in Yii framework and first of all what I
This is my first attempt at java problem I have been given as part
Ok guys, this is my first thread, and I have searched online but with
Hi guys this is my first question ever on SO so please go easy
Hey guys this is a bit of a homework puzzle I'm working on and

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.