使用AFNetworking的缓存在ios中不起作用
我的目标是在没有互联网连接的情况下显示数据。可能是我缺少如何缓存数据的概念。但到目前为止,我已经将AFHTTPRequestOperationManager子类化了使用AFNetworking的缓存在ios中不起作用,ios,caching,afnetworking,Ios,Caching,Afnetworking,我的目标是在没有互联网连接的情况下显示数据。可能是我缺少如何缓存数据的概念。但到目前为止,我已经将AFHTTPRequestOperationManager子类化了 @implementation MYHTTPRequestOperationManager - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request
@implementation MYHTTPRequestOperationManager
- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request
success:(void (^)(AFHTTPRequestOperation *operation,
id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation,
NSError *error))failure
{
NSMutableURLRequest *modifiedRequest = request.mutableCopy;
AFNetworkReachabilityManager *reachability = self.reachabilityManager;
if (!reachability.isReachable)
{
modifiedRequest.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
}
return [super HTTPRequestOperationWithRequest:modifiedRequest
success:success
failure:failure];
}
@end
在我的ApiAccess类中的getRequestWithUrl方法下:
- (void) getRequestWithUrl:(NSString*) url params:(NSDictionary*) params tag:(NSString*) tag
{
MYHTTPRequestOperationManager *manager = [MYHTTPRequestOperationManager manager];
[manager.requestSerializer setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[manager GET:[NSString stringWithFormat:@"%@%@",baseurl,url] parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
NSError* error = nil;
Response *response = [[Response alloc] initWithDictionary:responseObject error:&error];
if (response.responseStat.isLogin) {
[self.delegate receivedResponse:responseObject tag:tag index:0];
}
else
{
[JSONHTTPClient postJSONFromURLWithString:[NSString stringWithFormat:@"%@app/login/authenticate/accesstoken",baseurl] bodyString:[NSString stringWithFormat:@"access_token=%@",accessToken]
completion:^(NSDictionary *json, JSONModelError *err)
{
NSError* error = nil;
AccessTokenResponse *response = [[AccessTokenResponse alloc] initWithDictionary:json error:&error];
if(response.responseStat.status)
{
[self postRequestWithUrl:url params:params tag:tag];
}
}];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
//[self.delegate receivedError:error tag:tag];
}];
}
当互联网关闭时,一切都不会发生。
我应该怎么做才能让它正常工作