如何在UIWebView
中啓用緩存?如何在UIWebView中啓用緩存?
這很令人沮喪。我正在尋找幾個小時,但在其他許多帖子中沒有提到的解決方案對我沒有幫助。
我嘗試了許多解決方案,如https://stackoverflow.com/a/26174438,https://stackoverflow.com/a/1424301,http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/,https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/URLLoadingSystem/Concepts/CachePolicies.html,iOS Cache a UIWebView等
我的代碼看起來像
[self setUrl:[[NSString alloc] initWithFormat:@"http://example.com"]];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[self setLoadUrl: [NSURL URLWithString:[self url]]];
[self setRequestObj:[NSURLRequest requestWithURL:[self loadUrl]]];
如果caching
被禁用。如果它開啓我
if([[self cache] isEqualToNumber:[[NSNumber alloc] initWithInt:1]])
{
[[NSURLCache sharedURLCache] setDiskCapacity:4 * 1024 * 1024];
[[NSURLCache sharedURLCache] setMemoryCapacity:32 * 1024 * 1024];
[self setRequestObj:[NSURLRequest requestWithURL:loadUrl cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0]];
}
你可以試試這個網址https://lh4.ggpht.com/wKrDLLmmxjfRG2-E-k5L5BUuHWpCOe4lWRF7oVs1Gzdn5e5yvr8fj-ORTlBF43U47yI = w300並告訴我結果。 –
試試這個答案並實現NSMutableURLRequest http://stackoverflow.com/a/26174438/3116236 – iSashok
@iSashok我也試過這個答案,它也鏈接在我的文章。不幫助我......我錯了什麼? – Premox