Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nishabe/ef8b36452f4b1a6d5df5 to your computer and use it in GitHub Desktop.
Save nishabe/ef8b36452f4b1a6d5df5 to your computer and use it in GitHub Desktop.
OBJC:Calling Web service using NSURLSession & Blocks
// More at http://code.tutsplus.com/tutorials/networking-with-nsurlsession-part-1--mobile-21394
// More samples at: http://hayageek.com/ios-nsurlsession-example/
- (void)viewDidLoad {
[super viewDidLoad];
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *dataTask = [session dataTaskWithURL:[NSURL URLWithString:@"https://itunes.apple.com/search?term=apple&media=software"] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@", json);
}];
[dataTask resume];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment