views:

54

answers:

1

ok, nothing special here, no errors, and I do declare NSMutableData *receivedData; but I'm returning <> when I expect a web page returned; what's going on?

- (void)viewDidLoad {
    [super viewDidLoad];

    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com"]
                                           cachePolicy:NSURLRequestUseProtocolCachePolicy
                                           timeoutInterval:60.0];

    NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 

    if (theConnection) {
            receivedData = [[NSMutableData data] retain];
            NSLog(@"receivedData %@", receivedData);
    } else {
            // inform the user that the download could not be made
    }
}
+2  A: 

You seem to be referring to the "Using NSURLConnection" section of URL Loading System ... but it looks like you stopped reading directly after the code example you copied. Read the next section. You're only creating the data object to 'catch' the incoming data. More code is needed to actually handle the response and place it in your data object. It's not surprising that an immediate log afterward turns up nothing.

Joshua Nozzi
Yes, gosh do I feel dumb. Added the delegates, out the end I do spit out a bunch of bytes, assuming just need to transform those to readable text.
ed potter
Yes, but frankly, if you're planning on extracting readable text from a web page, you're probably better off using WebKit. Also, a high accept rate for answers helps improve your reputation, BTW (hint, hint). ;-)
Joshua Nozzi