1. <small id='096zR'></small><noframes id='096zR'>

    <i id='096zR'><tr id='096zR'><dt id='096zR'><q id='096zR'><span id='096zR'><b id='096zR'><form id='096zR'><ins id='096zR'></ins><ul id='096zR'></ul><sub id='096zR'></sub></form><legend id='096zR'></legend><bdo id='096zR'><pre id='096zR'><center id='096zR'></center></pre></bdo></b><th id='096zR'></th></span></q></dt></tr></i><div id='096zR'><tfoot id='096zR'></tfoot><dl id='096zR'><fieldset id='096zR'></fieldset></dl></div>
    <legend id='096zR'><style id='096zR'><dir id='096zR'><q id='096zR'></q></dir></style></legend>

      • <bdo id='096zR'></bdo><ul id='096zR'></ul>
      <tfoot id='096zR'></tfoot>

    1. UIWebView 和 NSURLCache 关系有问题

      UIWebView and NSURLCache have a troubled relationship(UIWebView 和 NSURLCache 关系有问题)
        <legend id='jMHrx'><style id='jMHrx'><dir id='jMHrx'><q id='jMHrx'></q></dir></style></legend>

          • <tfoot id='jMHrx'></tfoot>

          • <i id='jMHrx'><tr id='jMHrx'><dt id='jMHrx'><q id='jMHrx'><span id='jMHrx'><b id='jMHrx'><form id='jMHrx'><ins id='jMHrx'></ins><ul id='jMHrx'></ul><sub id='jMHrx'></sub></form><legend id='jMHrx'></legend><bdo id='jMHrx'><pre id='jMHrx'><center id='jMHrx'></center></pre></bdo></b><th id='jMHrx'></th></span></q></dt></tr></i><div id='jMHrx'><tfoot id='jMHrx'></tfoot><dl id='jMHrx'><fieldset id='jMHrx'></fieldset></dl></div>
              <tbody id='jMHrx'></tbody>
            • <bdo id='jMHrx'></bdo><ul id='jMHrx'></ul>

              <small id='jMHrx'></small><noframes id='jMHrx'>

                本文介绍了UIWebView 和 NSURLCache 关系有问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试解决 UIWebView 中的两件事:

                I am trying to solve 2 things in my UIWebView:

                1. 在适当的条件下加载本地资源代替远程资源
                2. 如果没有本地资源或它们已过时,则照常加载远程资源
                3. 允许 web 视图返回"而不需要从服务器重新加载它的 html

                为了处理#1 和#2,我实现了一个自定义子类NSURLCache.它在 webview 请求资产时被调用,而我可以发送本地的,中止服务器对资产的调用.我什至有一个小时间戳系统,它知道本地版本是否旧,以确定使用哪个版本.

                So to handle #1 and #2, I implemented a custom subclass NSURLCache. It gets called when the webview requests assets, and I can send along the local ones instead, aborting the server call for the asset. I even have a little timestamping system that knows if the local version is old or not to figure out which one to use.

                但是#3 让我陷入了循环.似乎不管缓存控制标头如何,UIWebView 总是会在返回时重新加载 HTML.

                But #3 is throwing me for a loop. It seems that regardless of cache-control headers, UIWebView will ALWAYS reload the HTML when going back.

                所以我尝试在我的自定义 NSURLCache 类中强制缓存 HTML.它似乎可以工作,并使用我想要的 HTML 返回 NSCachedURLResponse 的实例,但 UIWebView 没有注意到并从服务器加载它.经过一番搜索,我发现 UIWebView 和 url 缓存存在一些不一致",我想这是其中之一.对资产很有效,但对组成它试图显示的页面的 HTML 来说不是很好.

                So I tried to force caching of the HTML in my custom NSURLCache class. It seems to work, and returns the instance of NSCachedURLResponse with the HTML I want, but the UIWebView fails to notice and loads it from the server anyway. After some searching I see there is some "inconsistencies" with UIWebView and the url cache, and I guess this is one. Works great for assets, but not so great for the HTML that makes up the page it's trying to display.

                然后我决定,因为这可能行不通,所以手动进行.我创建了一堆 url,以及我手动获取并使用 loadData:MIMEType:textEncodingName:baseURL: 加载的数据.瞧,它似乎工作得很好!我现在可以回去了,Web 视图代理会拦截负载,并告诉它加载我手动获取的数据,这样服务器就不会被击中.

                So then I decided that since this may not work, do it manually. I created a stack of urls, and their data that I fetch manually and load it with loadData:MIMEType:textEncodingName:baseURL:. Lo and behold it seemed to work great! I could now go back, the web view delegate would intercept the load, and tell it to load my manually fetched data instead, and the server would not be hit.

                但是,我注意到 NSURLCache 不再用于我的资产.如果您使用 loadRequest: 加载内容而不是通过正确设置 baseUrl 加载数据或 html 字符串,它似乎只要求缓存资产.

                However, then I noticed that the NSURLCache was no longer being used for my assets. It seems it only asks for cached assets if you load content with loadRequest: and not by loading data or an html string with the baseUrl set properly.

                因此,尽管我付出了所有努力,但我还是无法让 Web 视图有条件地加载本地资产并在不访问服务器的情况下导航回来.看来我在 SDK 中有一些错误.

                So despite all my efforts I cannot make a web view conditionally load local assets AND navigate back without hitting the server. It seems like I have a few bugs here in the SDK.

                1. UIWebView 忽略服务器的 Cache-Control HTML 内容标头
                2. UIWebView 为主 HTML 请求请求 NSCachedURLResponse,但随后被忽略并丢弃.
                3. UIWebViewNSURLCache 询问资产,如果您通过请求加载它,但当加载 HTML 或数据时,它会完全绕过缓存并直接从远程服务器.
                1. UIWebView ignores the servers Cache-Control header for HTML content
                2. UIWebView asks for a NSCachedURLResponse's for the main HTML request but is then ignored and discarded.
                3. UIWebView asks the NSURLCache for assets if you load it up with a request, but when loading with HTML or data it bypasses the cache completely and requests it directly from the remote server.

                所以首先,有人找到解决这些问题的方法吗?其次,有什么理由说我很愚蠢而且这些实际上不是 SDK 错误?

                So first up, anyone see a solution to these things? And second, any reason that I am being stupid and these are not actually SDK bugs?

                推荐答案

                我已经放弃了这个.有太多的陷阱.相反,我只是通过 ajax 加载新页面.而不是 [webview goBack] 我有一些自定义 javascript 可以在 [webview stringByEvaluatingJavascriptFromString:@"goBack()"]

                I've abandoned this. There were just too many gotchas. Instead I just load new page in via ajax. And instead of [webview goBack] I have some custom javascript to do cool stuff for me on [webview stringByEvaluatingJavascriptFromString:@"goBack()"]

                这篇关于UIWebView 和 NSURLCache 关系有问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                iOS UIWebView app opens link in Safari(iOS UIWebView 应用在 Safari 中打开链接)
                Close UIWebView using javascript:window.close();(使用 javascript:window.close() 关闭 UIWebView;)
                NSCachedURLResponse returns object, but UIWebView does not interprets content(NSCachedURLResponse 返回对象,但 UIWebView 不解释内容)
                Trouble hiding iAd banner and displaying UIWebView in its place(无法隐藏 iAd 横幅并在其位置显示 UIWebView)
                Knowing when AJAX has loaded in UIWebView(知道何时在 UIWebView 中加载了 AJAX)
                Load image/logo in existing HTML input field - UIWebView(在现有的 HTML 输入字段中加载图像/徽标 - UIWebView)

                  <i id='I1Cjz'><tr id='I1Cjz'><dt id='I1Cjz'><q id='I1Cjz'><span id='I1Cjz'><b id='I1Cjz'><form id='I1Cjz'><ins id='I1Cjz'></ins><ul id='I1Cjz'></ul><sub id='I1Cjz'></sub></form><legend id='I1Cjz'></legend><bdo id='I1Cjz'><pre id='I1Cjz'><center id='I1Cjz'></center></pre></bdo></b><th id='I1Cjz'></th></span></q></dt></tr></i><div id='I1Cjz'><tfoot id='I1Cjz'></tfoot><dl id='I1Cjz'><fieldset id='I1Cjz'></fieldset></dl></div>

                    • <legend id='I1Cjz'><style id='I1Cjz'><dir id='I1Cjz'><q id='I1Cjz'></q></dir></style></legend>

                        <tfoot id='I1Cjz'></tfoot>
                          <tbody id='I1Cjz'></tbody>

                        <small id='I1Cjz'></small><noframes id='I1Cjz'>

                          <bdo id='I1Cjz'></bdo><ul id='I1Cjz'></ul>