title: Downloading a File with AFNetworking
body: <p>Trying to write a method for my iPhone program that given a URL address to a file, it would download to the iOS App's Documents Directory.</p>
  
  <p>Following AFNetowrking's Documentation, it seems to work fine except that the filename is always some garbage.</p>
  
  <p>I'm using Xcode 5 with AFNetworking 2.0 added to my project. Here's the code that I have so far:</p>
  
  <pre><code>//#import "AFURLSessionManager.h"
  
  //On load (or wherever):
  [self downloadFile:@"http://www.irs.gov/pub/irs-pdf/fw4.pdf"];
  
  -(void)downloadFile:(NSString *)UrlAddress
  { NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
  
  NSURL *URL = [NSURL URLWithString:UrlAddress];
  NSURLRequest *request = [NSURLRequest requestWithURL:URL];
  
  NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) 
  {
      NSURL *documentsDirectoryPath = [NSURL fileURLWithPath:[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]];
      return [documentsDirectoryPath URLByAppendingPathComponent:[targetPath lastPathComponent]];
  } 
  completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) 
  {
      NSLog(@"File downloaded to: %@", filePath);
  }];
  [downloadTask resume];
  }
  </code></pre>
  
  <p>The end result is that the file is successfully downloaded to my documents directory, but with a garbled name:</p>
  
  <p>File downloaded to: file:///Users/myname/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/25188DCA-4277-488E-B08A-4BEC83E59194/Documents/CFNetworkDownload_60NWIf.tmp</p>
  
  <p>The end result I'm expecting:</p>
  
  <p>File downloaded to: file:///Users/myname/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/25188DCA-4277-488E-B08A-4BEC83E59194/Documents/fw4.pdf</p>
  
  <p>I used cocoapods to add AFNetworking to my project:
  pod 'AFNetworking', "~> 2.0"</p>
  
  <p>Lastly, what do I need to do to get the progress of the download?</p>