// // LDCacheHttp.m // YouHuiProject // // Created by 小花 on 2018/5/10. // Copyright © 2018年 kuxuan. All rights reserved. // #import "KBCacheHttp.h" #import "ZmzAFNetworking.h" @implementation KBCacheHttp + (void)post:(NSString *)url params:(NSDictionary *)params success:(void(^)(id json,BOOL isCache))success failure:(void(^)(NSError *error))failure { YBCacheType cacheType = YBCacheTypeReturnCacheDataThenLoad; //如果不是第一页数据,就直接忽略缓存,直接请求真正的数据 if (params) { [params.allKeys containsObject:@"page"]; NSNumber *page = params[@"page"]; if (page.integerValue > 1) { cacheType = YBCacheTypeReloadIgnoringLocalCacheData; } } ZmzAFNetworking *networking = [[ZmzAFNetworking alloc]init]; [networking requsetWithPath:url withParams:params withCacheType:cacheType withRequestType:NetworkPostType withResult:^(id responseObject, NSError *error,BOOL isCache) { if (!error) { NSDictionary *dataDic = (NSDictionary *)responseObject[@"rst"]; success(dataDic,isCache); }else{ NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"]; NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"服务器的错误原因:%@",str); NSLog(@"报错地址:%@",url); failure(error); } }]; } + (void)get:(NSString *)url params:(NSDictionary *)params success:(void(^)(id json,BOOL isCache))success failure:(void(^)(NSError *error))failure { YBCacheType cacheType = YBCacheTypeReturnCacheDataThenLoad; if (params) { [params.allKeys containsObject:@"page"]; NSNumber *page = params[@"page"]; if (page.integerValue > 1) { cacheType = YBCacheTypeReloadIgnoringLocalCacheData; } } ZmzAFNetworking *networking = [[ZmzAFNetworking alloc]init]; [networking requsetWithPath:url withParams:params withCacheType:YBCacheTypeReturnCacheDataThenLoad withRequestType:NetworkGetType withResult:^(id responseObject, NSError *error,BOOL isCache) { if (!error) { NSDictionary *dataDic = (NSDictionary *)responseObject[@"rst"]; success(dataDic,isCache); }else{ NSData * data = error.userInfo[@"com.alamofire.serialization.response.error.data"]; NSString * str = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; NSLog(@"服务器的错误原因:%@",str); NSLog(@"报错地址:%@",url); failure(error); } }]; } @end