如何在UIWebview中删除缓存?

时间:2016-09-26 07:36:48

标签: ios objective-c caching uiwebview

我已经在webview中加载了网址,加载成功但是每当我再次点击它在缓存中显示两个网址并再次显示三个网址等时,它意味着它继续维护堆栈。我使用了很多方法,但工作不正常。

以下是我正在尝试的内容。

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];
 }

我也尝试了以下这些答案。

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

我正在做很多R& D但是没有找到解决这些问题的确切解决方案。

感谢。

2 个答案:

答案 0 :(得分:0)

我使用下面的代码来删除缓存,希望它适合你:

$groups = Model::where('active', 1)->get()->groupBy('type_id');

    foreach ($groups as $group) {
        $grouped[] =  $group->groupBy('configuration_id');
    }

答案 1 :(得分:-1)

Hayia,研究员! 研究了这个主题一段时间,发现了一个最适合我的解决方案 - 使用WKWebView它不泄漏! 就是这么 - 很简单。