Skip to content

Instantly share code, notes, and snippets.

@goooooouwa
Created December 21, 2015 09:12
Show Gist options
  • Select an option

  • Save goooooouwa/6b586884cfd1771d361c to your computer and use it in GitHub Desktop.

Select an option

Save goooooouwa/6b586884cfd1771d361c to your computer and use it in GitHub Desktop.
standard response handler in iOS with Objective-C
[[_session dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
NSHTTPURLResponse *httpResp = (NSHTTPURLResponse*) response;
if (httpResp.statusCode == 200) {
// 3
NSString *text =
[[NSString alloc]initWithData:data
encoding:NSUTF8StringEncoding];
dispatch_async(dispatch_get_main_queue(), ^{
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
self.textView.text = text;
});
} else {
// HANDLE BAD RESPONSE //
}
} else {
// ALWAYS HANDLE ERRORS :-] //
}
// 4
}] resume];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment