1

After looking up information regarding loading offline resources into UIWebView, it looks like I'm out of luck for any easy solution.

I can load my main html file very easily by doing the following

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"tour" ofType:@"html"]isDirectory:NO]]];

The problem is that all the images/etc inside that are inside folders in my resources do not load. If it is in the top level like tour.html is, then it does load.

The paths simply do not behave like paths as if it was on a server.

Chewie The Chorkie
  • 4,896
  • 9
  • 46
  • 90
  • are the paths to your resources relative or absolute? Pages loaded offline can load images etc fine so long as the paths are relative (e.g. ) and the images are included in your bundle too. Note that you should add a folder reference to folder containing your html rather than adding the files directly as xcode has a tendency to put everything flat into the same folder. – Ben Clayton Feb 29 '12 at 21:41
  • You can find an answer to your question in the following post http://stackoverflow.com/questions/6179786/ipad-loading-local-html-into-web-view-with-images-and-javascript – voromax Feb 29 '12 at 21:48
  • Thanks Ben, I guess I don't really know what you mean by adding a folder reference to folder containing my html rather than adding the files directly. What is a folder reference to folder? My paths are relative like you mentioned. – Chewie The Chorkie Feb 29 '12 at 21:50

1 Answers1

2

When you drag a folder of resources to XCode, select "Create folder references for any added folders" rather than the default "Create groups for any added folders".

Your folder icon will appear as blue - not yellow, which means it is a reference to the actual physical folder on disk.

It will then preserve its structure when added into the bundle.

Gilad Novik
  • 4,546
  • 4
  • 41
  • 58