title: Execute a method synchronously after a NSURLSession
body: <p>I'm currently trying to execute a method after a NSURLSession completes. The problem is I can't manage in any way the asynchronous nature of its object. I've tried with GCD and NSOperation as suggested in the other questions but nothing changes: after the initialization with <em>dataTaskWithRequest:completionHandeler:</em>, the application starts executing the next method in the program.</p>
  
  <p>Here is the method which realizes the networking: </p>
  
  <pre><code>-(void)sendData{
      NSData *JSONdata = [NSJSONSerialization dataWithJSONObject:userInfoToJSON options:0 error:&amp;error];
  
              NSURL *url = [NSURL URLWithString:@"http://mobdev2015.com/register.php"];
              NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
              NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[JSONdata length]];
  
              [request setHTTPMethod:@"POST"];
              [request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
              [request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
              [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
              [request setHTTPBody:JSONdata];
  
              [[session  dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
                  requestReply = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
              }]resume];
              });
  }
  </code></pre>
  
  <p>Here is the method instead which calls the one above and where I want to implement a synchronous execution:</p>
  
  <pre><code>-(void)MethodWhichNeedsToBeSync{
  //Creating a JSON object..
  [self sendData:userInfoToJSON];
  //MethodB wants to be executed if and only if sendData is completed
  [self MethodB];
  }
  </code></pre>
  
  <p>Thank you for the replies.</p>