title: Objective-C GET Request - How to not freeze the UI, and wait for response?
body: <p>I'm making a simple GET request using the following code:</p>
  
  <pre><code>NSString *urlStr = [@"http://192.168.1.107/Server.Mobile/test.ashx?rp="
                            stringByAppendingString:[rpText 
                                 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  
  NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlStr]                                                          
                                       cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData
                                       timeoutInterval:100];
  
  [request setHTTPMethod: @"GET"];
  
  NSError *requestError;
  NSURLResponse *urlResponse = nil;
  NSData *response1 = [NSURLConnection sendSynchronousRequest:request returningResponse:&amp;urlResponse error:&amp;requestError];
  NSString *txt = [[NSString alloc] initWithData:response1 encoding:NSUTF8StringEncoding];
  </code></pre>
  
  <p>But, while performing it, I'm trying to show an UIAlertView, and then dismiss it when the request is complete.</p>
  
  <p>I know how to show/hide the alert, but I can't manage to synchronize it with the request. The request freezes the UI, so when it is done the AlertView shows and hides instantly:</p>
  
  <pre><code>alert = [[UIAlertView alloc] initWithTitle:@"Please, wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
  [alert show];
  
  // ... Perform get request...
  
  [alert dismissWithClickedButtonIndex:0 animated:YES];
  </code></pre>
  
  <p>If I, on the other hand, assign the request to an async operation, like <code>dispatch_async</code>, I can't call the dismiss. It just doesn't close the AlertView</p>
  
  <pre><code>alert = [[UIAlertView alloc] initWithTitle:@"Please, wait..." message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
  [alert show];
  
  dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  
      // ... Perform get request...
  
      [alert dismissWithClickedButtonIndex:0 animated:YES];
  });
  </code></pre>
  
  <p><strong>How can I show the Alert, perform the request waiting for the response, and then close the Alert?</strong></p>
  
  <p>I'm new to iOS development...</p>