iOS 6 - UIWebView loadHTMLString无法正常工作 [英] iOS 6 - UIWebView loadHTMLString not working properly

查看:295
本文介绍了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?1312306173media =screen =stylesheettype =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,但它在收到webViewDidFinishLoad消息之前大约需要5分钟。 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出现后,我的网页浏览中出现了类似的问题。尝试将以下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无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆