1

how I can enable caching in an UIWebView?

It's frustrating. I'm looking for hours but no mentioned solutions in many other posts doesn't helped me.

I tried many solutions like https://stackoverflow.com/a/26174438, https://stackoverflow.com/a/1424301, http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/, https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Concepts/CachePolicies.html, iOS Cache a UIWebView, etc.

My code looks like

    [self setUrl:[[NSString alloc] initWithFormat:@"http://example.com"]];
    [[NSURLCache sharedURLCache] setDiskCapacity:0];
    [[NSURLCache sharedURLCache] setMemoryCapacity:0];
    [self setLoadUrl: [NSURL URLWithString:[self url]]];
    [self setRequestObj:[NSURLRequest requestWithURL:[self loadUrl]]];

if cachingis disabled. If it's turned on I have

if([[self cache] isEqualToNumber:[[NSNumber alloc] initWithInt:1]])
{
    [[NSURLCache sharedURLCache] setDiskCapacity:4 * 1024 * 1024];
    [[NSURLCache sharedURLCache] setMemoryCapacity:32 * 1024 * 1024];
    [self setRequestObj:[NSURLRequest requestWithURL:loadUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]];
}

How

Community
  • 1
  • 1
Premox
  • 323
  • 10
  • 25
  • Can you try this url https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI=w300 and tell me the results. – Ashraf Tawfeeq Jun 01 '16 at 07:49
  • Try this answer and implement NSMutableURLRequest http://stackoverflow.com/a/26174438/3116236 – iSashok Jun 01 '16 at 07:57
  • @iSashok I tried this answer too and it's also linked at my post. Doesn't helped me ... What did I wrong? – Premox Jun 01 '16 at 08:05
  • @iSashok Do I have implement something else? I tried it too and `[[self webView] loadRequest:[self request]];` is my NSMutableURLRequest – Premox Jun 01 '16 at 08:11
  • 1
    [I think you missed this](http://stackoverflow.com/a/16830262/1066828) – Fahim Parkar Jun 01 '16 at 09:01

1 Answers1

3

@Premox I think you can choose a different way. After your uiwebview loaded page you can get a response html convert to NSString class and save it to cache or serialize as you wanna

iSashok
  • 2,326
  • 13
  • 21