title: Downloading Image does now work with NSURLSessionDataTask
body: <p>I am migrating my deprecated iOS9 code to iOS10, specifically this:</p>
  
  <pre><code>@interface IconDownloader : NSObject&lt;NSURLConnectionDataDelegate,NSURLConnectionDelegate&gt;{
      NSMutableData *receivedData;
  }
  @property(nonatomic,strong)CapabilityType *capability;
  @property(nonatomic,strong)CapabilitiesItemView *item;
  -(void)downloadIcon:(CapabilityType *)capability forItem:(CapabilitiesItemView *)item;
  @end
  
  @implementation IconDownloader
  .
  .
  .
  .
  NSURLConnection *con=[[NSURLConnection alloc] initWithRequest:req delegate:self];
      [con start];
  
  -(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
      NSLog(@"DEPRECATED - didReceiveData"); 
      if(!receivedData){
          receivedData=[[NSMutableData alloc] initWithData:data];
      }else
          [receivedData appendData:data];
  }
  
  -(void)connectionDidFinishLoading:(NSURLConnection *)connection{
      NSLog(@"DEPRECATED - connectionDidFinishLoading"); 
      NSLog(@"NSURLConnection - COMPLETE, dataLength=%lu",(unsigned long)receivedData.length);
      NSLog(@"DataIOS7+: %@",receivedData);
      if(receivedData.length&gt;0){
          UIImage *image=[UIImage imageWithData:receivedData];
          if(image){
              self.capability.icon=image;
              self.item.iconImageView.image=image;
          }
      }
  </code></pre>
  
  <p>This deprecated, but reliable code works perfectly.
  When I try to do an adaptation for iOS10+, the <strong>image</strong> variable always is initialized as null, and my imageViews look blank:</p>
  
  <pre><code>NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:req
                                              completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){
                                        NSLog(@"NSURLSessionDataTask - COMPLETE, error=%@",error);
                                        if(!error){
                                            NSLog(@"NSURLSessionDataTask - COMPLETE, dataLength=%lu",(unsigned long)data.length);
                                            NSLog(@"DataIOS10: %@",data);
                                            if(data.length&gt;0){
                                                NSData *dataIOS10 = [[NSData alloc] initWithBase64EncodedString:[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] options:NSDataBase64DecodingIgnoreUnknownCharacters];
                                                UIImage *image=[UIImage imageWithData:dataIOS10];
  
                                                dispatch_async(dispatch_get_main_queue(), ^{
                                                if(image){
                                                    NSLog(@"NSURLSessionDataTask - COMPLETE, IMAGE OK");
                                                    self.capability.icon=image;
                                                    self.item.iconImageView.image=image;
                                                }
                                                else{
                                                    NSLog(@"NSURLSessionDataTask - COMPLETE, IMAGE ERROR");
                                                    self.capability.icon=image;//Lets try shoving that data there, just in case LOL
                                                    self.item.iconImageView.image=image;
                                                }
                                                });
                                            }
                                        }
                                    }];
  [dataTask resume];
  </code></pre>
  
  <p>EXTRA, the request appears to arrive fine:</p>
  
  <pre><code>NSURLSessionDataTask - COMPLETE, response=&lt;NSHTTPURLResponse: 0x15e450f0&gt; { URL: https://abc.SOMESERVER.net/prod/wcid/iphone/icon_fun.png } { status code: 200, headers {
      "Accept-Ranges" = bytes;
      Connection = "keep-alive";
      "Content-Length" = 6416;
      "Content-Type" = "image/png";
      Date = "Tue, 31 Jan 2017 13:11:05 GMT";
      Etag = "\"e554f6246076dc4eddf589f9552608b5\"";
      "Last-Modified" = "Mon, 28 Apr 2014 13:30:15 GMT";
      Server = AmazonS3;
      Via = "1.1 dc81da318a4ae20e51ccfd9463219596.cloudfront.net (CloudFront)";
      "X-Amz-Cf-Id" = "xlj4_3IUrjctZLrGlegXoZbrmTYqd_ahcGzG3K2glG3m6keedPk6mQ==";
      "X-Cache" = "Miss from cloudfront";
      "x-amz-meta-cb-modifiedtime" = "Thu, 31 Oct 2013 15:26:16 GMT";
  } }
  </code></pre>
  
  <p>The image will always be null, despite always having non zero byte size, and with or without that fancy Base64 encoding... it always fails. I even tried running the code on the main thread. Any ideas why?</p>