Skip to content

Instantly share code, notes, and snippets.

@Aquima
Created October 28, 2013 20:01
Show Gist options
  • Save Aquima/7203573 to your computer and use it in GitHub Desktop.
Save Aquima/7203573 to your computer and use it in GitHub Desktop.
Ejemplo de como usar NSURLSession
#import "WSConsult.h"
@interface WSConsult()<NSURLSessionDelegate>
@end
@implementation WSConsult
+(WSConsult *)sharedInstance {
static dispatch_once_t pred;
static WSConsult *shared = nil;
dispatch_once(&pred, ^{
shared = [[WSConsult alloc] init];
});
return shared;
}
+(void)getInfoFacebook{
NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *defaultSession = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
NSURL * url = [NSURL URLWithString:@"http://kodebinario.com/get"];
NSURLSessionDataTask * dataTask = [defaultSession dataTaskWithURL:url
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if(error == nil)
{
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
}
}];
[dataTask resume];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment