NSURLSession-SynchronousTask 1.0.0

NSURLSession-SynchronousTask 1.0.0

TestsTested
LangLanguage Obj-CObjective C
License MIT
ReleasedLast Release Jun 2015

Maintained by freemiumdev.



  • By
  • freemiumdev

NSURLSession+SynchronousTask

NSURLSession+SynchronousTask is an NSURLSession category which brings NSURLConnection-like (remember sendSynchronousRequest:returningResponse:error:?) synchronous tasks to NSURLSession.

Internally the category uses GCD to wait for the tasks to finish and NSURLSession's shared instance sharedSession to perform the tasks.

Usage

NSURLSessionDataTask

NSURL *url = ...
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLSession sendSynchronousDataTaskWithURL:url returningResponse:&response error:&error];
...

NSURLSessionDownloadTask

NSURL *url = ...
NSError *error = nil;
NSURLResponse *response = nil;
NSURL *fileURL = [NSURLSession sendSynchronousDownloadTaskWithURL:url returningResponse:&response error:&error];
...

NSURLSessionUploadTask

NSURLRequest *uploadRequest = ...
NSData *dataToBeUploaded = ...
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLSession sendSynchronousUploadTaskWithRequest:uploadRequest fromData:dataToBeUploaded returningResponse:&response error:&error];
...

Contact

Florian Schliep

License

NSURLSession+SynchronousTask is available under the MIT license. See the LICENSE.txt file for more info.