Last active
August 12, 2018 18:19
-
-
Save nishabe/ef8b36452f4b1a6d5df5 to your computer and use it in GitHub Desktop.
OBJC:Calling Web service using NSURLSession & Blocks
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
// 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