Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are couple of things you could do.</p> <ol> <li>You can use <code>sendAsynchronousRequest</code> and handle the callback block.</li> <li>You can use <code>AFNetworking</code> library, which handles all your requests in asynchronous fashion. Very easy to use and set up.</li> </ol> <p>Code for option 1:</p> <pre><code>NSURL *url = [NSURL URLWithString:urlString]; NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url]; NSOperationQueue *queue = [[NSOperationQueue alloc] init]; [NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) { if (error) { //NSLog(@"Error,%@", [error localizedDescription]); } else { //NSLog(@"%@", [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding]); } }]; </code></pre> <p>Code for option 2:</p> <p>You might want to download the library &amp; include it in your project first. Then do the following. You can follow the post on setting up <a href="https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking" rel="nofollow noreferrer">here</a></p> <pre><code>NSURL *url = [NSURL URLWithString:@"http://httpbin.org/ip"]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSLog(@"IP Address: %@", [JSON valueForKeyPath:@"origin"]); } failure:nil]; [operation start]; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload