written by http://nscookbook.com/2013/03/ios-programming-recipe-16-populating-a-uitableview-with-data-from-the-web/
I need to show a UIWebView that opens a local html, fetching from a remote server. Each time, the UIWebView shows incorrect data, because the iOS caching system.
I did many attempts to solve this problem, but it does not work:
1) Programmatically add UIWebView when the UIViewController starts loading. After the UIViewController disappears, stop loading the UIWebView, and release the UIWebView.
2) Ignore the local cache data:
NSURL *websiteUrl = [NSURL fileURLWithPath:localHtmlPath];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:websiteUrl];
[request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
[self.webView loadRequest:request];
3) Clear the cache when the UIViewController disappears
[[NSURLCache sharedURLCache] removeAllCachedResponses];
for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
if([[cookie domain] isEqualToString:localHtmlPath]) {
[[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];
}
}
4) Disable the cache
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
}
5) Reduce iOS memory utilization by taming NSURLCache
follow the tutorial link
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
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];
}
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application
{
[[NSURLCache sharedURLCache] removeAllCachedResponses];
}
6) Follow this link to prevent CSS caching.
None of these above methods works. Any workaround?
2 similar answers β
Try this may be help full ....
NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0 diskCapacity:0 diskPath:nil]; [NSURLCache setSharedURLCache:sharedCache]; [sharedCache release];
Thanks & cheers
You seem to have tried almost everything. I'm aware you are rejecting the cookies. Yet, Why dont you try this? This worked for me...
NSHTTPCookie *aCookie; for (aCookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) { [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:aCookie]; }
'모바일개발(Mobile Dev) > IOS개발(ObjectC)' 카테고리의 다른 글
splash screen for all types of iPhones in XCode 6.1? (0) | 2015.12.13 |
---|---|
background thread in iOS (0) | 2015.12.12 |
How do I clear the data in a plist created in XCode? (0) | 2015.12.12 |
A better way to access NSUserDefaults (0) | 2015.12.11 |
Sending Image from Xcode to Server (0) | 2015.12.11 |