title: NSURLSession delegate methods are not called
body: <p>I'm trying to update an old application to move from NSURLConnection to NSURLSession. Everything works fine when I use blocks for NSURLSession:</p>
  
  <pre><code> NSURLSessionDataTask *dataTask = [session
                                            dataTaskWithRequest:request 
   completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {}
  </code></pre>
  
  <p>But sometimes I need to analyse the data that the app is receiving from server, so I need didReceiveResponse and didReceiveData methods, similar to the ones used with NSURLConnection. I'm trying to do it like this:</p>
  
  <pre><code> NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  
   NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration
                                                        delegate:self
                                                   delegateQueue:nil];
   NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://www.apple.com"]];
   [dataTask resume];
  </code></pre>
  
  <p>But my delegates are never called:</p>
  
  <pre><code>- (void)URLSession:(NSURLSession *)session
   NSURLSessionTaskDelegatedidReceiveResponse:(NSURLResponse *)response
   completionHandler:(void (^)(NSURLSessionResponseDisposition disposition))completionHandler
  {
      NSLog(@"-----------------------&gt; NSURLSessionTaskDelegatedidReceiveResponse");
      completionHandler(NSURLSessionResponseAllow);
  }
  - (void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask didReceiveData:(NSData *)data
  {
      NSLog(@"----------------&gt; didReceiveData");
  }
  </code></pre>
  
  <p>Same thing happens when I'm trying to use other types of tasks (NSURLSessionDownloadTask for example), their delegates are never called. I can actually see in the debugger that the tasks are switching to running state, but I can never get any calls to delegates. 
  In my header file I do conform my ViewController to delegates:</p>
  
  <pre><code>@interface ViewController : UIViewController &lt;NSURLSessionDelegate, NSURLSessionDataDelegate, NSURLSessionTaskDelegate&gt;
  </code></pre>
  
  <p>I did quite a bit of searching but even when I'm trying some working examples from the web they just stop working as soon as I try to paste them in my project. For example <a href="http://toomanytutorials.blogspot.ru/2015/03/nsurlsession-with-delegates.html" rel="nofollow noreferrer">this tutorial</a> works perfectly for me (I do have to add Transport Security permissions to plist file, but that's about it). But when I'm trying to use this code in my project delegates are never called. And when I'm actually paste my code to another simple application it works just fine. So something probably wrong with my project's settings? Could you please show me what can cause something like this? I'm completely bewildered at the moment.</p>