Note that there are some explanatory texts on larger screens.

plurals
  1. PONSURLConnection with ARC not receiving Data
    primarykey
    data
    text
    <p>I'm fairly new to iOS Development and I'm trying to get content from an URL. I'm using the Apple tutorial for using NSURLConnection, everything is working but I'm not getting data. I've looked around and couldn't find an answer to my problem. I'm also using ARC in my project, maybe that causes the problem?</p> <p>Here is the code I'm using, starting with my header file:</p> <pre><code>@interface ViewController : UIViewController @property (nonatomic, retain) NSMutableData *receivedData; @end </code></pre> <p>implementation file:</p> <pre><code>@implementation ViewController @synthesize receivedData; - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Release any cached data, images, etc that aren't in use. } - (void)viewDidLoad { [super viewDidLoad]; NSLog(@"1. viewDidLoad"); // Create the request NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.apple.com/"] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]; // Create the connection with the request and start loading the data NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self]; if (connection) { NSLog(@"2. connection succeeded"); receivedData = [NSMutableData data]; } else { NSLog(@"2. connection failed"); } } - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { NSLog(@"3. didReceiveResponse"); [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [receivedData appendData:data]; } - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { NSLog(@"4. Connection failed! Error - %@ %@", [error localizedDescription], [[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]); } - (void)connectionDidFinishLoading:(NSURLConnection *)connection { NSLog(@"4. Succeeded! Received %d bytes of data", [receivedData length]); } </code></pre> <p>All the NSLog are working, but it keeps saying receivedData has 0 bytes. I couldn't find an answer to my problem so I hope I can find my answer with this question.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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