美文网首页iOS个人修养IOSiOS开发工具
[FGNetwork]A light networking ki

[FGNetwork]A light networking ki

作者: CGPointZero | 来源:发表于2016-09-13 18:27 被阅读45次

    FGNetwork

    ..............................................................

    Introduction

    A light networking kit for iOS with GET ,POST,file upload and multi files uploading supported,base on NSURLSession.

    Installtion

    Manual:

    Download This Project and drag the FGNetwork folder into your peroject, do not forget to ensure "copy item if need" being selected.

    Usage

    Just import the header file:import "FGNetwork.h"

    Singleton

    /**
     *  Singleton
     */
    +(instancetype)shared;
    

    GET:

    /**
     *  get请求
     *  urlString   链接
     *  success     成功的回调
     *  failure     失败的回调
     */
    -(void)get:(NSString *)urlString success:(void (^) (NSData *data, NSURLResponse *response)) success failure:(void (^) (NSError *error))failure;
    

    POST:

    /**
     *  post请求
     *  urlString   主地址
     *  paramaters  参数字典
     *  success     成功的回调
     *  failure     失败的回调
     */
    -(void)post:(NSString *)urlString paramaters:(NSString *)paramaters success:(void (^) (NSData *data, NSURLResponse *response)) success failure:(void (^) (NSError *error))failure;
    

    And file upload supported:

    /**
     *  文件上传
     *  urlString   服务器地址
     *  fileData    文件二进制数据
     *  mimeType    MIME Type
     *  paramaters  参数字典
     *  success     成功的回调
     *  failure     失败的回调
     */
    -(void)uploadFileToHost:(NSString *)urlString fileData:(NSData *)fileData name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType paramaters:(NSString *)paramaters success:(void (^) (NSData *data, NSURLResponse *response)) success failure:(void (^) (NSError *error))failure;
    

    Multi files upload supported:

    /**上传多张照片(2张)file应该对应多个变量名儒file0,file1*/
    -(void)uploadMultiFileToHost:(NSString *)urlString imgs:(NSArray *)imgs name:(NSString *)name mimeType:(NSString *)mimeType paramaters:(NSString *)paramaters success:(void (^)(NSData *data, NSURLResponse *response))success failure:(void (^)(NSError *error))failure;
    

    And a optional function:

    /**
     *  取消所有数据请求
     */
    -(void)cancelAllDataTask;
    

    Example

    -(void)downloadData{
        
        [[FGNetwork shared] get:@"http://www.baidu.com" success:^(NSData *data, NSURLResponse *response) {
            
            NSString *str=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
            NSLog(@"%@",str);
            
        } failure:^(NSError *error) {
            
        }];
    }
    

    About Me

    Blog: CGPointZeero
    GitHub: Insfgg99x
    Mooc: CGPointZero
    Jianshu: CGPointZero
    Email: newbox0512@yahoo.com

    I attached my code on github,touch to download ->FGNetwork
    ..............................................................

    @CGPoitZero


    相关文章

      网友评论

        本文标题:[FGNetwork]A light networking ki

        本文链接:https://www.haomeiwen.com/subject/thnmettx.html