iOS 6 - UIWebView loadHTMLString not working properly(iOS 6 - UIWebView loadHTMLString 无法正常工作)
问题描述
如果有人遇到以下问题,请告诉我您是否能够找到解决方法.我花了几天时间试图想出一个解决方案,但到目前为止还没有运气.我正在使用 XCode 4.5 和 iOS 6 SDK Golden Master.
If anyone experienced the issue below, please let me know if you were able to find a fix. I've spent a couple of days trying to come up with a solution, but no luck so far. I'm using XCode 4.5 with iOS 6 SDK Golden Master.
基本上,我的应用程序读取 HTML 文件并将其内容交给 Web 视图进行渲染.
Basically, my application reads and HTML file and hands its contents to a web view for rendering.
NSString *path = [[NSBundle mainBundle] pathForResource:@"filename" ofType:@"html"];
NSString *html = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:NULL];
NSURL *baseURL = [NSURL URLWithString:@"http://mysite.com"];
[webView loadHTMLString:html baseURL:baseURL];
HTML 包含几个 <link>标签,例如:<link href="/webshare/accounts/maxk/styles/mobile_app_iphone_article.css?1312306173" media="screen" rel="stylesheet" type="text/css"/>
The HTML contains a few <link> tags, for instance: <link href="/webshare/accounts/maxk/styles/mobile_app_iphone_article.css?1312306173" media="screen" rel="stylesheet" type="text/css" />
问题是,UIWebView 似乎无法下载 CSS 文件.UIWebViewDelegate 确实会立即收到 webViewDidStartLoad,但它需要大约 5 分钟才能收到 webViewDidFinishLoad 消息.CSS 没有被拾取.
The problem is, UIWebView seems to have troubles downloading the CSS file. The UIWebViewDelegate does receive webViewDidStartLoad right away, but it takes about 5 minutes before it receives webViewDidFinishLoad message. CSS is not picked up.
如果我从 HTML 中删除链接,一切正常.
If I remove the link from HTML, everything works normally.
推荐答案
iOS 6 发布后,我的 Web 视图出现了类似的问题.尝试将以下 UIWebView 属性设置为 true (YES) {仅在 iOS 6+ 中可用}:
I had a similar issue in my web views once iOS 6 came out. Try setting the following UIWebView property to true (YES) { only available in iOS 6+ }:
suppressesIncrementalRendering
A Boolean value indicating whether the web view suppresses content rendering until it is
fully loaded into memory.
@property(nonatomic) BOOL suppressesIncrementalRendering
基本上在我的情况下,异步内容加载会产生一些以前不存在的奇怪竞争条件.我花了一段时间才找到那个.不过,我也同意 Brian 的观点 - 使用一些代理软件并观察您的流量,以验证您需要的所有东西都在进来以及什么时候进来.这可能非常有用.
Basically in my circumstances the async content loading created a bit of an odd race condition that wasn't there before. Took me a while to find that one. I also agree with Brian though -- use some proxy software and watch your traffic to verify everything you need is coming in and when it comes in. That can be very useful.
如果有帮助,请告诉我?
Let me know if it helps?
这篇关于iOS 6 - UIWebView loadHTMLString 无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 6 - UIWebView loadHTMLString 无法正常工作
基础教程推荐
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01