CocoaPods trunk is moving to be read-only. Read more on the blog, there are 10 months to go.

BETURLSession 1.0.1

BETURLSession 1.0.1

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

Maintained by Jose Camallonga.



  • By
  • Seivan Heidari and Screen Interaction

Using NSURLSession and the rest of the new iOS 7 & Mavericks foundation network classes, wrapped with syntactic sugar and convenience. No need to inherit and make a singleton. The category will keep track of your session with a session name.

Overview

A incredibly light weight and source-readable HTTP client. Plugginable Serializers on top of builting foundation classes NSURLSession and NSURLSessionTask. Life-cycle callbacks (think before_filter or after_filter) Upload & Download progress blocks. Choose delegates and/or blocks Convenience serializers (JSON out of the box by default) to get started fast.

Installation

pod 'BETURLSession'

Setup

#import <BETURLSession.h>

API

Documentation for now

Sample

  NSURLSession * session = [NSURLSession bet_sessionWithName:@"Random" baseURLString:@"http://httpbin.org"];

  NSMutableArray * bigData = @[].mutableCopy;
  for (NSInteger i = 0; i!=50000; i++) [bigData addObject:@(i)];

  NSURLSessionTask * task = [session bet_taskPOSTResource:@"post" 
                                               withParams:@{@"POST" : bigData} 
                                               completion:^(BETResponse *response) {
    NSLog(@"POST completed with code %@ & error %@", 
                @(response.HTTPURLResponse.statusCode), 
                  response.error
          );
  }];

  BETURLSessionTaskProgressHandlerBlock (^progressHandlerWithName)(NSString *) = ^BETURLSessionTaskProgressHandlerBlock(NSString * name) {
    return ^(NSURLSessionTask *task, NSInteger bytes, NSInteger totalBytes, NSInteger totalBytesExpected) {
      NSLog(@"%@ : %@ <-> %@ <-> %@", name, @(bytes), @(totalBytes), @(totalBytesExpected));
    };
  };



  [task bet_setUploadProgressHandler:progressHandlerWithName(@"Upload")];

  [task bet_setDownloadProgressHandler:progressHandlerWithName(@"Download")];

  [task resume];

Notes

  • Proper naming
  • completion: for callbacks that are complete (option)
  • completionHandler: callbacks that are complete but need action (required)
  • handler: callbacks that need action but are not necessarily completion (required)

Contact

If you end up using BETURLSession in a project, we'd love to hear about it.

email: [email protected]
twitter: @ScreenTwitt

License

BETURLSession is © 2013 Screen Interaction and may be freely distributed under the MIT license. See the LICENSE.md file.