1

I am creating an iOS Application working in offline mode by using a AFNetworking library.

To manage a HTTP request I have defined a AFHTTPRequestOperationManager

- (AFHTTPRequestOperationManager *)requestOperationManager
{
    if (!_requestOperationManager)
    {
        _requestOperationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:[NSURL URLWithString:SERVICE_BASE_URL]];
    }

    return _requestOperationManager;
}

To load a HTTP request I have defined a method:

- (void)loadRequest
{
    if (!self.internetConnectionAvaliable)
    {
        self.requestOperationManager.requestSerializer.cachePolicy = NSURLRequestReturnCacheDataElseLoad;
    }

    NSString *url = SERVICE_METHOD_URL;

    NSDictionary *parameters = @{@"password" : USER_PASSWORD, @"username" : USER_NAME};

    [self.requestOperationManager POST:url parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        NSString *htmlString = [NSString stringWithFormat:@"%@", [responseObject objectForKey:@"view"]];

        [self.webView loadHTMLString:htmlString baseURL:nil];
    }

    failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"ERROR!!!" message:@"ERROR!!!" delegate:nil cancelButtonTitle:@"CANCEL" otherButtonTitles:nil];

        [alertView show];
    }];
}

When internet connection is enabled, AFNetworking loads desired data perfectly. When internet connection is disabled, AFNetworking doesn't load any data. This makes me think, that data caching doesn't work as it should!

Does anyone knows why? How to fix it?

Daumantas Versockas
  • 797
  • 1
  • 10
  • 29

0 Answers0