Note that there are some explanatory texts on larger screens.

plurals
  1. PONo Data Returned Using NSURLConnection Asynchronously
    primarykey
    data
    text
    <p>I am having a heck of time with something that seems rather<br> straightforward but I can't seem to get working. I am building an<br> iPhone app that retrieves data from a web host. I am trying to<br> establish an asynchronous connection to the host as I want to keep the<br> device freed up during the connection. (sendSynchronousRequest freezes<br> the phone until the request is done.) Here is my connection code:</p> <pre><code>//temp url to see if data is returned: NSURL *theURL = [NSURL URLWithString:@"http://www.theappleblog.com/feed"]; NSURLRequest *dataRequest = [NSURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60]; /* establish the connection */ theConnection = [[NSURLConnection alloc] initWithRequest:dataRequest delegate:self startImmediately:YES]; if (theConnection == nil) { NSLog(@"Connection Failure!"); self.urlData = nil; } else { self.urlData = [[NSMutableData data] retain]; } </code></pre> <p>I have all of the appropriate delegate methods set up:</p> <pre><code>-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse*)response { [urlData setLength:0]; UIApplication *application = [UIApplication sharedApplication]; application.networkActivityIndicatorVisible = YES; NSLog(@"Received Response!"); } </code></pre> <p><code></code></p> <pre><code>-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)incrementalData { [self.urlData appendData:incrementalData]; NSNumber *resourceLength = [NSNumber numberWithUnsignedInteger:[self.urlData length]]; NSLog(@"resourceData length: %d", [resourceLength intValue]); NSLog(@"filesize: %d", self.urlDataSize); NSLog(@"float filesize: %f", [self.urlDataSize floatValue]); } </code></pre> <p><code></code></p> <pre><code>-(void)connectionDidFinishLoading:(NSURLConnection*)connection { NSLog(@"Connection finished loading\n"); NSLog(@"Succeeded! Received %d bytes of data",[urlData length]); _isFinished = YES; UIApplication *application = [UIApplication sharedApplication]; application.networkActivityIndicatorVisible = NO; } </code></pre> <p><code></code></p> <pre><code>- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"Error: %@",[error localizedDescription]); } </code></pre> <p>As you can see, I've got a boat-load of log messages because I wanted<br> to see if <em>anything</em> was coming through at all. My connection test<br> comes back as TRUE but no data ever gets loaded. Like I said, I'm sure<br> I must be doing (or not doing) something <em>really</em> stupid. But what?<br> Any help would be most appreciated.</p> <p>Thanks, Lawrence</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload