title: Second asynchronous NSURLConnection doesn't call delegate methods
body: <p>From my ApplicationDelegate, I'm doing an NSURLConnection fetch over the network (it's wrapped in a class, as you'll see below). This one seems to work correctly: I get all the data in didReceiveData and I get the completion call connectionDidFinishLoading. At the end of connectionDidFinishLoading, I instantiate one or more of a slightly different kind of wrapper class, but they're essentially the same thing. The problem is that the second NSURLConnection's delegate is never having it's methods called.</p>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/3319943/nsurlconnection-doesnt-call-delegate-methods">many</a> <a href="https://stackoverflow.com/questions/3421054/nsurlconnection-delegate-methods-not-executing">different</a> <a href="https://stackoverflow.com/questions/4702294/nsurlconnection-hanging-on-second-call">answers</a>, but all to no avail. I'm not spawning any new threads and all the [NSThread isMainThread] checks I've littered throughout the code return true.</p>
  
  <p>I'm stumped. Can anyone help me out? Here's the relevant code:</p>
  
  <p>App Delegate:</p>
  
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  
      ConnectionWrapper* w = [[ConnectionWrapper alloc] initWithParams:self
      url:[NSURL URLWithString:&lt;url&gt;]];
  [w beginFetch];
  
      return YES;
  }
  
  ...
  
  -(void)fetchCompleted:(NSURL*)url directory:(NSString*)directory
  {
  NSLog(@"fetch completed");
  }
  
  -(void)fetchFailed:(NSURL*)url
  {
  NSLog(@"fetch failed");
  }
  
  ...
  </code></pre>
  
  <p>ConnectionWrapper:</p>
  
  <pre><code>-(id)initWithParams:(id&lt;ConnectionWrapperDelegate&gt;)d url:(NSURL*)url
  {
      delegate = d;
  
      connURL = url;
  
      return [self init];
  }
  
  -(void)beginFetch
  {
      NSURLRequest* request = [[NSURLRequest alloc] initWithURL:connURL];
      NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  
      [conn release];
      [request release];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
      NSLog(@"append");
      [responseData appendData:data];
  }
  
  - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  {
      ... parsing ....
  
      DifferentConnectionWrapper* w = [[DifferentConnectionWrapper alloc] initWithParams:self
          url:[NSURL URLWithString:&lt;different url&gt;]];
      [w beginFetch];
  }
  
  -(void)fetchCompleted:(NSURL*)URL
  {
      NSLog(@"completed: %@", URL);
  }
  
  -(void)fetchFailed:(NSURL*)URL
  {
      NSLog(@"failed");
  }
  </code></pre>
  
  <p>DifferentConnectionWrapper:</p>
  
  <p>-(id)initWithParams:(id)d url:(NSURL*)url
      {
          delegate = d;</p>
  
  <pre><code>    connURL = url;
  
      return [self init];
  }
  
  -(void)beginFetch
  {
      NSURLRequest* request = [[NSURLRequest alloc] initWithURL:connURL];
      NSURLConnection* conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  
      [conn release];
      [request release];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
      NSLog(@"append");
      [responseData appendData:data];
  }
  
  - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  {
      ... parsing ....
  
      DifferentConnectionWrapper* w = [[DifferentConnectionWrapper alloc] initWithParams:self
          url:[NSURL URLWithString:&lt;different url&gt;]];
      [w beginFetch];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  {
      NSLog(@"got response");
      [responseData setLength:0];
  }
  
  - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
      NSLog(@"got data");
      [responseData appendData:data];
  }
  
  - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  {
      NSLog(@"image saver completed: %@", connURL);
  }
  
  - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  {
      NSLog(@"error");
  }
  </code></pre>
  
  <p>ConnectionWrapper and DifferentConnectionWrapper have similar functions, but there's other logic that I've omitted here for brevity.</p>
  
  <p>thanks for the help. I appreciate it.</p>