Question

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 ?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top