-1

I'm using a UIWebView in an iOS application and it won't stop loading in old assets. My index.html references multiple javascript files that don't seem to update unless I clean the build folder, and even then they can sometimes persist. I can remove the folder with the html, css and javascript from the project, delete it and still build and run with it displaying in the web view.

My AppDelegate clears the cache with

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

after 'didFinishLaunchingWithOptions'. I then add the files to the web view with:

NSURL *mainBundleURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]];
NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[_webView loadHTMLString:htmlString baseURL:mainBundleURL];

I have also tried loading the files with a request, but I get the same results.

NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:0 timeoutInterval:60.0];
[self.webView loadRequest:request];

I have tried adding the folder as a folder reference and group reference in the project. The folder can be found in the Copy Bundle Resources. I've started over with creating a new project, but the problem was still there.

It seems like such a simple issue, but I've tried everything I can find online.

1
  • If this is a simulator issue, try resetting the sim. Also, you may want to try one of these... NSURLRequestUseProtocolCachePolicy = 0, NSURLRequestReloadIgnoringLocalCacheData = 1, NSURLRequestReloadIgnoringLocalAndRemoteCacheData =4, NSURLRequestReloadIgnoringCacheData = NSURLRequestReloadIgnoringLocalCacheData, NSURLRequestReturnCacheDataElseLoad = 2, NSURLRequestReturnCacheDataDontLoad = 3, NSURLRequestReloadRevalidatingCacheData = 5 Commented Jun 7, 2014 at 12:57

1 Answer 1

1

Try this may be help full ....

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

Thanks & cheers

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

1 Comment

Still getting the same results, though it cleared the cache on the first run.

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.