iOS 6 - UIWebView loadHTMLString 无法正常工作

iOS 6 - UIWebView loadHTMLString not working properly(iOS 6 - UIWebView loadHTMLString 无法正常工作)

本文介绍了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 无法正常工作

基础教程推荐