简体   繁体   English

iPhone应用程序-RSS feed和loadHTMLString:baseURL的问题:

[英]iPhone App - Issue with RSS feed and loadHTMLString:baseURL:

I'm parsing an RSS feed (which comes in as an XML) and loading it into a UIWebView - and that works perfectly well. 我正在解析RSS提要(以XML形式出现)并将其加载到UIWebView中-效果很好。 The problem is with the occasional <img> tags that are in the XML - the images they call aren't showing up (although I do get a placeholder bounding-box where they should be appearing.) 问题出在XML中偶尔出现的<img>标记-他们调用的图像没有显示(尽管我确实在应显示它们的位置显示了一个占位符边框)。

The issue is that those <img> tags unfortunately contain only partial paths, with no domain name - for example: 问题是不幸的是,那些<img>标记仅包含部分路径,没有域名-例如:

<img src="/news-media/images/football/6.jpg" />

To fix that I tried specifying the default domain name in the baseURL argument: 要解决此问题,我尝试在baseURL参数中指定默认域名:

NSURL *baseURL = [NSURL fileURLWithPath:@"http://www.myDomain.com"];
[theWebView loadHTMLString:tempHtmlString baseURL:baseURL];

This does not work - the HTML is still loading fine, but the images are not showing up. 这不起作用-HTML仍然可以正常加载,但是图像没有显示出来。 This does however eliminate the "broken image" icons I was getting before on the images (the kind you usually get when a web-page is trying to load an image that's missing.) Also, I sometimes get a "received memory warning" message - but not always. 但是,这确实消除了我以前在图像上收到的“图像损坏”图标(当网页尝试加载丢失的图像时通常会获得的图标)。此外,有时还会收到“收到内存警告”消息- 但不总是。 Seems to happen when loading a page that contains multiple photos. 加载包含多张照片的页面时似乎会发生。 But even when a page has only one photo and I do not receive the "memory" warning, the photo itself doesn't get loaded. 但是,即使页面上只有一张照片并且我没有收到“内存”警告,照片本身也不会被加载。

Any ideas what to do? 有什么想法怎么办? Am I gonna have to manually append the base-URL to all occurrences of the <img> tag? 我是否必须将base-URL手动附加到所有<img>标签?

You are creating your base URL as a file URL (ie a URL to a local file on the device). 您正在将基本URL创建为文件URL(即设备上本地文件的URL)。 You want the URL To reference the remote server. 您希望URL引用远程服务器。 Try this: 尝试这个:

NSURL *baseURL = [NSURL URLWithString:@"http://www.myDomain.com"];
[theWebView loadHTMLString:tempHtmlString baseURL:baseURL];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM