Created
May 13, 2018 03:20
-
-
Save an-indya/e7119831be1a336b1f17e83a0c5f97c1 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
-(IBAction)didPressConnectButton:(id)sender { | |
NSURL *url = [NSURL URLWithString:@"http://someurl.com/api?parameter"]; | |
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; | |
self.connection1 = [[NSURLConnection alloc] initWithRequest:request delegate:self]; | |
} | |
#pragma mark - NSURLConnectionDataDelegate Methods | |
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { | |
self.responseData = [[NSMutableData alloc] init]; | |
} | |
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { | |
[self.responseData appendData:data]; | |
} | |
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { | |
if ([connection isEqual: self.connection1]) { | |
NSData *data = self.responseData; | |
//Do something with the data | |
} | |
} | |
#pragma mark - NSURLConnectionDelegate Methods | |
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error { | |
//Handle error scenario | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment