Search code examples
iosobjective-cwikipediawebarchive

Wikipedia Images aren't loading from a webarchive in UIWebView


I am loading some Wikipedia pages from a webarchive (created in desktop Safari) in a UIWebView. This allows the pages to be available offline.

However, for some reason the images aren't loading when offline. It appears that they are being loaded from the website.

Everything worked fine in the past and I've noticed that the problem only effects new webarchives created after Wikipedia updated their mobile website format.

It's strange because the images load when offline if I open the webarchive on my computer, but not in iOS.

Any idea what's going on here?

I'm using the following code to load the 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]];

Update: I also found out that loading a webarchive in mobile safari made from the mobile wikipedia site will cause a crash in iOS 7.

Here is a link to a new webarchive that is causing problems and one from the old version of Wikipedia that works fine. I've changed the file extension to "plist" so they can easily be edited. Change back to "webarchive" to test.

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

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


Solution

  • Ilnar is correct. Expanding on his answer, the attribute srcset is not supported in iOS7 srcset support This is most likely what is causing the crash you are seeing.

    Srcset is used to provide multiple image links for different device sizes all in one image tag. There is javascript at the beginning that finds the right src for the image return'srcset'in new Image();

    The NEW webarchive is using this tag to provide links to 3 images. The OLD webarchive simply uses the tag to point to a URL.

    Srcset should be supported in iOS8 but it looks like wikipedia is using a resolution tag of 1.5x and 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 (the backbone of Safari) only supports whole numbers (1x,2x,3x). So this could be causing the failed load on iOS 8.