Created
December 21, 2015 09:12
-
-
Save goooooouwa/6b586884cfd1771d361c to your computer and use it in GitHub Desktop.
standard response handler in iOS with Objective-C
This file contains hidden or 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
| [[_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