3

Specifically -- how do you get all the assets to load from their respective directories (images/, css/, js/) without changing the content of the original HTML (removing directories)?

I am using this code to load index.html into the UIWebview:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"index" withExtension:@"html"];
NSString *html = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];

NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];

[webView loadHTMLString:html baseURL:baseURL];

Then my html looks like this:

...
<link rel="stylesheet" type="text/css" href="css/main.css" />
<script type="text/javascript" src="js/classes.js"></script>
<script type="text/javascript" src="js/animate.js"></script>
etc...

If I remove the js/, css/, and images/, everything works because iOS thinks everything is in the root of my bundle. But, that means I cant use the same code across projects without dumping it all into one directory (lame). The engineer in me can't deal with this kind of disorganization.

Thanks in advance.

Edz
  • 558
  • 4
  • 8

2 Answers2

3

Easy: when you add the folder(s) to Xcode, make sure you add them as folder references.

They will then be added as folders to the .app bundle:

Community
  • 1
  • 1
Kenneth Ballenegger
  • 2,970
  • 2
  • 19
  • 25
1

You should be able to do this. The important thing to note is how files are added to your project. When adding files via Xcode, make sure to check "Create folder references for any aded folders", and NOT "Create groups for any added folders".

reference

Community
  • 1
  • 1
Bob Kinney
  • 8,870
  • 1
  • 27
  • 35