Skip to content

Instantly share code, notes, and snippets.

@nawafuji
Created June 9, 2014 05:01
Show Gist options
  • Save nawafuji/d3cddc48f5929d5c543b to your computer and use it in GitHub Desktop.
Save nawafuji/d3cddc48f5929d5c543b to your computer and use it in GitHub Desktop.
NSURL* url = [NSURL URLWithString:[_urlString stringByAppendingString:@"messages"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60.0];
void (^handler)(NSURLResponse* response, NSData* data, NSError* error);
handler = ^(NSURLResponse* response, NSData* data, NSError* error){
NSString* result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
if (data == nil) {
NSLog(@"Connection failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
return;
}
NSJSONSerialization* _jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
if (_jsonObject == nil) {
NSLog(@"JSON data parsing failed! Error - %@ %@",
[error localizedDescription],
[[error userInfo] objectForKey:NSURLErrorFailingURLStringErrorKey]);
self._dataTextView.text = [error description];
return;
}
};
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue currentQueue]
completionHandler:handler];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment