如何在AFHTTPRequestOperationMnager中缓存响应

时间:2015-03-09 08:56:11

标签: ios

这是我的代码。我设置了cachePolicy = DontLoad,但它仍然从服务器获取数据而不是从本地缓存中获取数据。为什么呢?

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataDontLoad;

    AFHTTPResponseSerializer *responseSerializer = [AFHTTPResponseSerializer serializer];
    responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    manager.responseSerializer = responseSerializer;
    [manager GET:@"http://www.github.com" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"%@", [[NSString alloc]initWithData:responseObject encoding:NSUTF8StringEncoding]);

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

    }];

0 个答案:

没有答案