LYNetworkRequestKit
由 本人 独立 设计 开发 的 网络 请求 框架, 支持对 网络 请求 hud 的 显示, 支持点击 hud 背景 取消 某个 网络 请求 的 操作, 支持 http get 请求 缓存
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 并返回给逻辑层
- get 返回一个 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;
- get 返回 model 数组
-(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;
- post 返回一个 model
--(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;
- post 返回 model 数组
-(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;
使用方法
pod 'LYNetworkRequestKit'
pod install
待办事项列表(TODOLIST)
- 编写Swift版本
- 继续优化代码及使用方法等
变更日志(CHANLOG)
- 设置有效超时时间...修复之前超时时间无效的问题
- 设置HUD,添加全局配置项,设置UIActivityIndicatorView颜色为浅灰色