2

I have loaded the url in webview, loading is successful but whenever I hit again its show two url in cache and again its show three url etc. it means it continues to maintain the stack. I am using a lot of method but not working properly.

These are following what i am trying till now.

1.

[[NSURLCache sharedURLCache] removeCachedResponseForRequest:NSURLRequest];


[[NSURLCache sharedURLCache] removeAllCachedResponses];

for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {

if([[cookie domain] isEqualToString:someNSStringUrlDomain]) {

    [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}

2.

int cacheSizeMemory = 4*1024*1024; // 4MB
int cacheSizeDisk = 32*1024*1024; // 32MB
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:cacheSizeMemory diskCapacity:cacheSizeDisk diskPath:@"nsurlcache"];
[NSURLCache setSharedURLCache:sharedCache];

3.

 NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
[sharedCache release];

4.

-(void) viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];

[self.webView removeFromSuperview];
self.webView.delegate = nil;
self.webView = nil;
}

5.

[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];

6.

- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.webView stopLoading];
}
- (void) stopLoading {
[self.webView stopLoading];
self.webView.delegate = nil;
NSBundle *mainBundle = [NSBundle mainBundle];
NSURL *homeIndexUrl = [mainBundle URLForResource:@"Home" withExtension:@"html"];
NSURLRequest *urlReq = [NSURLRequest requestWithURL:homeIndexUrl];
[self.webView loadRequest:urlReq];
[EALoaderView hideLoaderForView:self.view animated:YES];
[self.webView loadHTMLString:html baseURL:nil];
 }

I have also try from these following Answer.

1.Clearing UIWebview cache

2.NSURLProtocol isn't asked to load after YES response to canInitWithRequest

3.How To Clear A UIWebView

4.How to delete the cache from UIWebview or dealloc UIWebview

5.How to clear UIWebView cache?

6.UIwebview without Cache

I am doing a lot of R&D but not found the exact solution to resolve these things.

Thanks.

2 Answers 2

0

I use the code bellow to delete cache, wish it works for you:

//This must be called in Main Thread
+ (void)clearWebCache
{
 //http://stackoverflow.com/questions/31289838/how-to-delete-wkwebview-cookies
    //https://github.com/ShingoFukuyama/WKWebViewTips
    //http://stackoverflow.com/questions/27105094/how-to-remove-cache-in-wkwebview/32491271#32491271
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"9.0")) {
        NSSet *websiteDataTypes = [NSSet setWithArray:@[WKWebsiteDataTypeDiskCache,
                                                        //WKWebsiteDataTypeOfflineWebApplicationCache,
                                                        WKWebsiteDataTypeMemoryCache,
                                                        //WKWebsiteDataTypeLocalStorage,
                                                        //WKWebsiteDataTypeCookies,
                                                        //WKWebsiteDataTypeSessionStorage,
                                                        //WKWebsiteDataTypeIndexedDBDatabases,
                                                        //WKWebsiteDataTypeWebSQLDatabases
                                                        ]];
        //// All kinds of data
        //            NSSet *websiteDataTypes = [WKWebsiteDataStore allWebsiteDataTypes];
        //// Date from
        NSDate *dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
        //// Execute
        [[WKWebsiteDataStore defaultDataStore] removeDataOfTypes:websiteDataTypes modifiedSince:dateFrom completionHandler:^{
            // Done
        }];
    }
    else {
        NSHTTPCookie *cookie;
        NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (cookie in [storage cookies]) {
            [storage deleteCookie:cookie];
        }
        [[NSURLCache sharedURLCache] removeAllCachedResponses];
    }
}

Sign up to request clarification or add additional context in comments.

Comments

-1

Hayia, Fellows! researched this theme for a while and found a solution that works for me the best - use WKWebView it doesn't leak! That's it - so simple.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.