gpt4 book ai didi

uiwebview - 在 iOS 8 上共享 NSURLCache 和 UIWebView

转载 作者:行者123 更新时间:2023-12-03 08:12:10 26 4
gpt4 key购买 nike

在 iOS 7 中,我能够将共享 URL 缓存设置为 NSURLCache 的子类。和任何 UIWebView ■ 我创建的每个请求都会自动使用该共享缓存。

// Set the URL cache and leave it set permanently
ExampleURLCache *cache = [[ExampleURLCache alloc] init];
[NSURLCache setSharedURLCache:cache];

但是,现在在 iOS 8 中,UIWebView 似乎不会从共享缓存和 cachedResponseForRequest 中提取。永远不会被调用。

有没有人找到此更改的文档或解决方法?

最佳答案

我今天遇到了同样的问题。在 ios7 上没问题,在 ios8 上坏了。

诀窍是创建您自己的缓存作为您在 didFinishLaunchingWithOptions 中做的第一件事。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// IMPORTANT: call this line before anything else. Do not call [NSURLCache sharedCache] before this because that
// creates a reference and then we can't create the new cache.
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil];

[NSURLCache setSharedURLCache:URLCache];

...

您可以在其他应用程序中看到这一点:

https://github.com/AFNetworking/AFNetworking/blob/master/Example/AppDelegate.m

这个站点虽然很旧,但有更多关于为什么你不应该在上面的代码之前调用 [NSURLCache sharedInstance] 的信息:
http://inessential.com/2007/02/28/figured_it_the_heck_out

关于uiwebview - 在 iOS 8 上共享 NSURLCache 和 UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25853470/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com