User Tools

Site Tools


This is an old revision of the document!


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 more concise implementation than NSURLConnection. 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.1393440870.txt.gz · Last modified: 2014/02/26 12:54 (external edit)