Skip to content

Instantly share code, notes, and snippets.

@an-indya
Created May 13, 2018 03:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save an-indya/e7119831be1a336b1f17e83a0c5f97c1 to your computer and use it in GitHub Desktop.
Save an-indya/e7119831be1a336b1f17e83a0c5f97c1 to your computer and use it in GitHub Desktop.
-(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