ios synchronous network request handler returning result
<p>The issue I am having is that my application has a thread that periodically needs make a series of network requests inside of a loop. Since this is inside of a separate thread and due to the nature of the requests (to a device on the local network and the response is simple) I want to do this synchronously. Network communication is a separate <code>networking</code> class than <code>databaseController</code> class.</p>

<p>I cannot get the method in <code>networking</code> class to return something from inside a completion handler</p>

<pre><code>+ (void)GetMessages
{
   NSURLSession *session = [NSURLSession sharedSession];
   NSURLRequest *request = [networking makeAuthenticatedRequest:@"subpath.html"];
   //NSString* returnable;
   NSURLSessionDataTask *task = [session dataTaskWithRequest:request
                                   completionHandler:
                              ^(NSData *data, NSURLResponse *response, NSError *error) {
                                  NSString* newStr = [[NSString alloc] initWithData:data
                                                         encoding:NSUTF8StringEncoding];
                                  //returnable = newStr;
                                  //return(newStr)
                                  NSLog(newStr);
                              }];
   [task resume];
}
</code></pre>

<p>the above code works but does not do anything except print the result of the request. when I try any of the commented out additions and the requisite changes nothing works. I have even tried to pass a reference to the calling object and update a property for storing the newStr inside the completion handler but even that does not work.</p>

<p>Is what I am trying possible? If so how?</p>

<p>I should probably add that the code needs to be compatible with ios 7-9.</p>