使用 NSURLSession 和其他新 iOS 7 & Mavericks 基础网络类,通过语法糖和便利性封装。无需继承和创建单例。该类别会根据会话名称跟踪您的会话。
一个轻量级且可读的 HTTP 客户端。基于内置的基础类 NSURLSession 和 NSURLSessionTask 的可插入序列化器。生命周期回调(如 before_filter 或 after_filter)、上传 & 下载进度块。您可以选择代理和/或块 自动序列化器(默认为 JSON)以快速入门。
pod 'BETURLSession'
#import <BETURLSession.h>
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];
如果在项目中使用 BETURLSession,我们很乐意听到您的反馈。
电子邮件:[email protected]
推特:@ScreenTwitt
BETURLSession 是 © 2013 Screen Interaction,可以免费根据 MIT 许可证 分发。请参阅 LICENSE.md
文件。