如何在 UIWebView 中启用缓存?
How to enable caching in UIWebView?
如何在 UIWebView
中启用缓存?
真令人沮丧。我正在寻找几个小时,但许多其他帖子中没有提到的解决方案对我没有帮助。
我尝试了很多解决方案,例如, , 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]];
}
如何
@Premox 我想你可以选择不同的方式。在您的 uiwebview 加载页面后,您可以获得响应 html 转换为 NSString class 并将其保存到缓存或序列化,如您所愿
如何在 UIWebView
中启用缓存?
真令人沮丧。我正在寻找几个小时,但许多其他帖子中没有提到的解决方案对我没有帮助。
我尝试了很多解决方案,例如, , 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]];
}
如何
@Premox 我想你可以选择不同的方式。在您的 uiwebview 加载页面后,您可以获得响应 html 转换为 NSString class 并将其保存到缓存或序列化,如您所愿