Created
June 9, 2014 05:01
-
-
Save nawafuji/d3cddc48f5929d5c543b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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