一套包括网络请求、HUD/HUD点击取消请求api、get缓存、

2018-11-24  本文已影响21人  老王技术栈

LYNetworkRequestKit 是一款AFNetworking进行的二次封装的网络请求框架

1、基础使用方法:

[[ExamSubRequest shareInstance] requestGetJsonOperationWithParam:nil action:@"getDataList" showLoadHud:YES cancelEnable:YES normalResponse:^(NSInteger status, id  _Nonnull data) {
        //成功回调
    } exceptionResponse:^(NSError * _Nonnull error) {
        //失败回调
    }];

2、针对单个请求设置网络请求设置、

ExamSubRequest * request1 =  [ExamSubRequest shareInstance];
    request1.loadCacheFirst = YES;//允许优先从缓存加载
    request1.refreshCache = YES;//允许刷新当前缓存
    [request1 requestGetJsonOperationWithParam:nil action:@"getDataList"
                                   showLoadHud:YES cancelEnable:YES
                                normalResponse:^(NSInteger status, id  _Nonnull data) {
        
    } exceptionResponse:^(NSError * _Nonnull error) {
        
    }];

3、对某个请求类设置全局请求设置、

//允许优先从缓存加载
-(BOOL)loadCacheFirst
{
    return YES;
}
//允许刷新当前缓存
- (BOOL)refreshCache{
    return YES;
}

下面方法允许直接网络请求数据解析成对应model返回数据给逻辑层

-(void)requestGetJsonModelWithParam:(NSDictionary *)param
                              action:(NSString *)action
                         showLoadHud:(BOOL)showHud
                        cancelEnable:(BOOL)cancelEnable
                          modelClass:(Class)modelClass
                      normalResponse:(void(^)(NSInteger status, id data, NSObject *model))normalResponse
                   exceptionResponse:(void(^)(NSError *error))exceptionResponse;
-(void)requestGetJsonArrayWithParam:(NSDictionary *)param
                              action:(NSString *)action
                         showLoadHud:(BOOL)showHud
                        cancelEnable:(BOOL)cancelEnable
                          modelClass:(Class)modelClass
                      normalResponse:(void(^)(NSInteger status, id data, NSMutableArray *array))normalResponse
                   exceptionResponse:(void(^)(NSError *error))exceptionResponse;
--(void)requestPostJsonModelWithParam:(NSDictionary *)param
                               action:(NSString *)action
                          showLoadHud:(BOOL)showHud
                         cancelEnable:(BOOL)cancelEnable
                           modelClass:(Class)modelClass
                       normalResponse:(void(^)(NSInteger status, id data, NSObject *model))normalResponse
                    exceptionResponse:(void(^)(NSError *error))exceptionResponse;
-(void)requestPostJsonArrayWithParam:(NSDictionary *)param
                               action:(NSString *)action
                          showLoadHud:(BOOL)showHud
                         cancelEnable:(BOOL)cancelEnable
                           modelClass:(Class)modelClass
                       normalResponse:(void(^)(NSInteger status, id data, NSMutableArray *array))normalResponse
                    exceptionResponse:(void(^)(NSError *error))exceptionResponse;

Github、欢迎star 或者issue

上一篇下一篇

猜你喜欢

热点阅读