title: Downloading a file from PHP function in iOS
body: <p>I'm trying to download a file from a PHP service in my iOS app.  I use the same PHP service from Android and from the browser and the server part works fine.  I can test the url in the browser and prompts to download the file like you'd expect.
  Also I can download the files just fine if I point the url directly at the file from my iOS code.  These are zip files.  I have to use this method because I need to get the file by id and I have to pass a access token string.  These validate OK so they aren't the problem.</p>
  
  <p>When I connect I get a didReceiveResponse with a httpResponse status code of 200 which I'm to believe is OK.  I then get a connectionDidFinishLoading delegate call but never get any data or errors in between.  </p>
  
  <p>Here is my connect code:</p>
  
  <pre><code>- (BOOL)downloadFile:(NSString *)fileName:(int)fileId
  {
      BOOL retVal = FALSE;
  
      NSString *strUrl = [NSString stringWithFormat:@"%@?id=%d&amp;token=%@", FILE_URL,   fileId, accessToken];
  
      NSURL *myURL = [NSURL URLWithString:strUrl];
  
      NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:myURL  cachePolicy:NSURLRequestReloadIgnoringLocalCacheData                                   timeoutInterval:60];
  
  
  //  Starts the download
  connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
  
  return TRUE;
  }
  </code></pre>
  
  <p>//  Here is the Response code:</p>
  
  <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
  {
      NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
  
      int code = [httpResponse statusCode];
  
      if(code &lt;= 200)
      {
          [responseData setLength:0];
      }
      else
      {
          NSString *msg = [NSString stringWithFormat:@"Error Code: %d.  Download has Failed.", code];
  
          UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Download Error!"
                                                      message:msg
                                                     delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
          [alert show];
      }
  }
  </code></pre>
  
  <p>//  This is the lonely receive data method.  Never gets called</p>
  
  <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
  {
      [responseData appendData:data];
  }
  </code></pre>
  
  <p>// Failure delegate method, doesn't get called either</p>
  
  <pre><code>- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  {
  
      NSString *msg = [NSString stringWithFormat:@"Error: %@", [error localizedDescription]];
  
      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Download Error!"
                                                  message:msg
                                                 delegate:nil
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
      [alert show];
  
  }
  </code></pre>
  
  <p>Like I said it works from Android and the browser and If I just point the url at the file it will download fine.</p>
  
  <p>I'm stuck and I appreciate any assistance I can get.</p>