0

i have an app that loads pdf file from server in UIWebView

when i change the pdf file from the server it does't changes in the app, i tried all this methods

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:request];

[[NSURLCache sharedURLCache] removeAllCachedResponses];

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
    if([[cookie domain] isEqualToString:MyURLString]) {
        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
    }
}

still the new pdf file doesn't change , sometimes it take some time to change and sometimes it don't

is there any other methods ?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
aLFaRSi
  • 559
  • 2
  • 12
  • 29
  • I'm interested to know the answer to this. We had to subclass NSURLProtocol to get cache clearing in a UIWebView, so it would be useful to know if there's an easier way. – Darren Feb 21 '14 at 22:14
  • Can u please explain how to subclass NSURLProtocol if its working with you please ? @Darren – aLFaRSi Feb 21 '14 at 22:33

1 Answers1

1

it's weird that neither [[NSURLCache sharedURLCache] removeAllCachedResponses]; nor [[NSURLCache sharedURLCache] removeAllCachedResponses]; works for you.

you may try one more (although not nice) trick:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    if(request.cachePolicy != NSURLRequestReloadIgnoringLocalCacheData) {
        NSURLRequst* noCacheRequest = [[NSURLRequest alloc] initWithURL:request.URL cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:request.timeoutInterval];
        [webView loadRequest:noCacheRequest];
        return false;
    }
    else
        return true;
}

also, try setHTTPShouldHandleCookies:, like here

Community
  • 1
  • 1
DaTa
  • 229
  • 1
  • 7
  • Can you please explain how exactly ? , tried the **setHTTPShouldHandleCookies** and still not working for me – aLFaRSi Feb 21 '14 at 22:34
  • I've updated the comment with the function implementation. it's not nice and I haven't tried it, so just have I try, hopefully it will help you. Good luck! – DaTa Feb 21 '14 at 23:10
  • Thank you for your help, the file is chaining but still taking some time to change :) – aLFaRSi Feb 21 '14 at 23:26