NSURLSession SynchronousTask Save

NSURLSession category which brings NSURLConnection-like synchronous tasks to NSURLSession

Project README

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.

Installation

CocoaPods is the recommended method of installing NSURLSession-SynchronousTask. Simply add the following line to your Podfile:

Podfile

pod 'NSURLSession-SynchronousTask'

Usage

NSURLSessionDataTask

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

NSURLSessionDownloadTask

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

NSURLSessionUploadTask

NSURLRequest *uploadRequest = ...
NSData *dataToBeUploaded = ...
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [[NSURLSession sharedSession] 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.

Open Source Agenda is not affiliated with "NSURLSession SynchronousTask" Project. README Source: floschliep/NSURLSession-SynchronousTask
Stars
73
Open Issues
2
Last Commit
8 years ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating