维基百科图像不是从UIWebView中的webarchive加载的

时间:2015-03-04 21:55:02

标签: ios objective-c wikipedia webarchive

我正在UIWebView中从webarchive(在桌面Safari中创建)加载一些维基百科页面。这允许页面脱机使用。

但是,出于某种原因,图片在离线时无法加载。它们似乎是从网站上加载的。

过去一切运作良好,我注意到这个问题只会影响维基百科更新移动网站格式后创建的新网络广告

这很奇怪,因为如果我在计算机上打开webarchive而不是在iOS中,则在离线时会加载图像。

知道这里发生了什么吗?

我使用以下代码加载webarchive:



NSString *fileName=[[NSString alloc] initWithFormat:@"%@", appDelegate.urlName];

NSString *htmlPath=[[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];

NSURL *url=[NSURL URLWithString:[htmlPath lastPathComponent] relativeToURL:[NSURL fileURLWithPath:[htmlPath stringByDeletingLastPathComponent] isDirectory:YES]];

[self.myWebView loadRequest:[NSURLRequest requestWithURL:url]];




更新:我还发现在移动维基百科网站上加载移动版Safari中的webarchive会导致iOS 7崩溃。

这是一个新的webarchive的链接,它引起了一些问题,一个来自旧版维基百科的工作正常。我已将文件扩展名更改为" plist"所以他们可以轻松编辑。改回" webarchive"测试。

(新)https://dl.dropboxusercontent.com/u/20616325/Badger%20%28NEW%29.plist

(OLD)https://dl.dropboxusercontent.com/u/20616325/Badger%20%28OLD%29.plist

2 个答案:

答案 0 :(得分:3)

即使您将页面添加为“完整网页”,其中图像也是单独存储的,也是相对路径。它不会加载它们,因为它们将奇怪的代码添加到omg标记中,例如

<img alt=".." src="relative_path(//upload.. in the relapse)" srcset="tahat_causes_problems" data-file-width="" data-file-height="" />
  

srcset =“// upload.wikimedia.org/wikipedia/commons/thumb/8/82/Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg/330px-Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg   1.5x,//upload.wikimedia.org/wikipedia/commons/thumb/8/82/Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg/440px-Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg   2x“data-file-width =”2124“data-file-height =”1416“

我使用wright相对路径向Xcode项目添加了一个完整的网页,加载到webView,没有IMGAES。但是,当我摆脱这个srcset =“..”,其余的它被装好了。

答案 1 :(得分:2)

Ilnar是对的。扩展他的答案,iOS7 srcset support不支持属性srcset。这很可能是导致您看到崩溃的原因。

Srcset用于在一个图像标记中为不同的设备大小提供多个图像链接。在开头有javascript找到图像return'srcset'in new Image();

的正确src

新的webarchive正在使用此标记提供3个图像的链接。 OLD webarchive只使用标记指向URL。

在iOS8中应该支持Srcset,但看起来维基百科使用1.5x和2x的分辨率标签。

`srcset="//upload.wikimedia.org/wikipedia/commons/thumb/8/82/Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg/270px-Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg 1.5x, //upload.wikimedia.org/wikipedia/commons/thumb/8/82/Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg/360px-Taxidea_taxus_%28Point_Reyes%2C_2007%29.jpg 2x

Webkit(Safari的骨干)仅支持整数(1x,2x,3x)。因此,这可能会导致iOS 8上的加载失败。