- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
UIWebView
似乎并不总是在加载资源时调用 storeCachedResponse:forRequest:
。有谁知道为什么?我正在尝试使用 -[NSURLCache storeCachedResponse:forRequest:]
来缓存图像,它可以很好地完成大部分工作,但在某些情况下 UIWebView
不会调用此方法在实际有图像的页面加载上。
最佳答案
回答赏金提供者的查询:
I'm seeing this for small files (100s of bytes) as well. The webview also fails to call
cachedResponseForRequest:
我找到了 this question直接解决此行为:
Despite Apple's documentation indicating otherwise,
NSURLCache
on iOS doesn't do any disk (flash) caching at all. You can subclassNSURLCache
to change the behaviour of the fetch and store operations to use the disk (likeSDURLCache
does), but due to the following severe limitations of how the cache is used and implemented, this doesn't work as well as you'd expect:
NSURLConnection
doesn't even callstoreCachedResponse:forRequest:
for files over about 50KB (>= 52428 bytes, to be exact). This makes subclassingNSURLCache
pointless for our use (200KB images), because it won't even get to the cache. As a result, we have to add caching manually at a level aboveNSURLConnection
.Even when one calls the NSURLCache's built-in
storeCachedResponse:forRequest:
manually, it only stores the response in memory if it's less than about 180KB. I tested this by calling storeCachedResponse manually and seeing that the before/aftercurrentMemoryUsage
didn't change for data lengths above about 180KB. So we have to write our own LRU memory caching too.
(强调我的。)
这似乎是引起行为的原因。作为the current accepted answer points out , ASIHTTPRequest是此行为的预期解决方法。
但是,请注意页面顶部的警告:
Please note that I am no longer working on this library - you may want to consider using something else for new projects. :)
您应该考虑依赖受支持的库,或者,如果您愿意,一旦它成为您的代码的基础,就回馈给这个库。
关于iphone - UIWebView 并不总是调用 -[NSURLCache storeCachedResponse :forRequest:],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9039144/
UIWebView 似乎并不总是在加载资源时调用 storeCachedResponse:forRequest:。有谁知道为什么?我正在尝试使用 -[NSURLCache storeCachedRes
刚刚发现函数 storeCachedResponse(_ cachedResponse: CachedURLResponse, for request: URLRequest) 异步工作。即执行后不会
我是一名优秀的程序员,十分优秀!