FGNetwork:A light networking kit for iOS base on NSURLSession

###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

1
2
3
4
/**
 *  Singleton
 */
+(instancetype)shared;

GET:

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

POST:

1
2
3
4
5
6
7
8
/**
 *  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:

1
2
3
4
5
6
7
8
9
10
/**
 *  文件上传
 *  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:

1
2
/**上传多张照片(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:

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

##Example

1
2
3
4
5
6
7
8
9
10
11
-(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