BANetworking

加入收藏
已有 3 人收藏

介绍:
    一个非常好用的网络框架-BANetworking。

    可用于创建网络请求,upload和download网络任务。

    使用 ARC 和依赖于 NSURLSession, BANetworking 支持 iOS 7.0 以上和 Mac OS X 10.9

    以上。

    

    使用说明:

    1. 初始化请求日志

    [BANetworking setDebugEnabled:YES];

    2. 创建下载任务

    BARequest *request = [BARequest GETRequestWithURL:[NSURL URLWithString:@"http://127.0.0.1/avatar"] parameters:nil];

    [[[[BAClient currentClient] performRequest:request] onComplete:^(BAResponse *result, NSError *error) {

    }] onProgress:^(float progress) {

     NSLog(@"download progress = %f",progress);

    }];

    3. 创建上传任务

    BARequest *request = [BARequest POSTRequestWithPath:path parameters:nil];

    request.contentType = BARequestContentTypeMultipart;

    request.fileData = [BARequestFileData fileDataWithData:data name:fileName fileName:[NSString stringWithFormat:@“%@.png",fileName]];

    [[[BAClient currentClient] performRequest:request] onComplete:^(id result, NSError *error) {

     if (error) {

     NSLog(@"file upload error");

     } else {

     NSLog(@"file upload succeed");

     }

    }];

测试环境:
  [Code4App]编译测试
效果图:
  • iOS / iPhone / iPad 一个非常好用的网络框架-BANetworking。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;可用于创建网络请求,upload和download网络任务。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;使用 ARC 和依赖于 NSURLSession, BANetworking 支持 iOS 7.0 以上和 Mac OS X 10.9 <br /><br />&nbsp;&nbsp;&nbsp;&nbsp;以上。<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;使用说明:<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;1. 初始化请求日志<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;[BANetworking setDebugEnabled:YES];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;2. 创建下载任务<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;BARequest *request = [BARequest GETRequestWithURL:[NSURL URLWithString:@"http://127.0.0.1/avatar"] parameters:nil];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;[[[[BAClient currentClient] performRequest:request] onComplete:^(BAResponse *result, NSError *error) {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;}] onProgress:^(float progress) {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;  NSLog(@"download progress = %f",progress);<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;}];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;3. 创建上传任务<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;BARequest *request = [BARequest POSTRequestWithPath:path parameters:nil];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;request.contentType = BARequestContentTypeMultipart;<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;request.fileData = [BARequestFileData fileDataWithData:data name:fileName fileName:[NSString stringWithFormat:@“%@.png",fileName]];<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;[[[BAClient currentClient] performRequest:request] onComplete:^(id result, NSError *error) {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;    if (error) {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;        NSLog(@"file upload error");<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;    } else {<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;        NSLog(@"file upload succeed");<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;    }<br /><br />&nbsp;&nbsp;&nbsp;&nbsp;}];
代码评论:
登录后方可评论

  
  • 暂无评论