User Tools

Site Tools


ios-labs-s14:basics-nsurl

NSURLSession

An iOS object that handles all network communication. Used to interact with the internet using HTTP.

Builds an HTTP request and fires it off to a URL. Returns the information provided by the server.

Uses a block to provide reactive functionality. Code inside the block is executed when the call completes, allowing for a concise method of handling responses. Data is returned in binary format and must be converted (usually with NSJSONDeserializer).

Sample Code (@“URL” is the target):

NSURLSession *session = [NSURLSession sharedSession];
[[session dataTaskWithURL:[NSURL URLWithString:@"URL"] 
        completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
            // handle response here, process NSData object
}] resume];
ios-labs-s14/basics-nsurl.txt · Last modified: 2014/02/26 12:55 by mbarboi