BETURLSession 1.0.1

BETURLSession 1.0.1

测试已测试
语种语言 Obj-CObjective C
许可证 MIT
发布最新发布2015年4月

Jose Camallonga 维护。



  • Seivan Heidari 和 Screen Interaction

使用 NSURLSession 和其他新 iOS 7 & Mavericks 基础网络类,通过语法糖和便利性封装。无需继承和创建单例。该类别会根据会话名称跟踪您的会话。

概述

一个轻量级且可读的 HTTP 客户端。基于内置的基础类 NSURLSession 和 NSURLSessionTask 的可插入序列化器。生命周期回调(如 before_filter 或 after_filter)、上传 & 下载进度块。您可以选择代理和/或块 自动序列化器(默认为 JSON)以快速入门。

安装

pod 'BETURLSession'

设置

#import <BETURLSession.h>

API

目前为文档

示例

  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];

注意事项

  • 正确的命名
  • completion: 用于已完成的回调(可选)
  • completionHandler: 需要执行动作的已完成回调(必需)
  • handler: 需要执行动作但未必是完成回调的回调(必需)

联系

如果在项目中使用 BETURLSession,我们很乐意听到您的反馈。

电子邮件:[email protected]
推特:@ScreenTwitt

许可证

BETURLSession 是 © 2013 Screen Interaction,可以免费根据 MIT 许可证 分发。请参阅 LICENSE.md 文件。