123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- //
- // DRCacheHttp.m
- // YouHuiProject
- //
- // Created by 小花 on 2018/5/10.
- // Copyright © 2018年 kuxuan. All rights reserved.
- //
- #import "DRCacheHttp.h"
- #import "ZmzAFNetworking.h"
- @implementation DRCacheHttp
- + (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);
- 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{
- failure(error);
- }
-
- }];
- }
- @end
|