I’m using a UIWebview to display content provided within local HTML files.
The problem however is that the page is not displaying correctly, only the core html is rendered with no css styles or media content displayed. For this project, I have the entire web structure in their respective folders and are placed within the Xcode project (all content is displayed within blue folders).
The built application package contains the web folders and all of content is there so I am unsure as to why it is not displaying correctly.
Here is the code I am using to load and display the webpage:
NSString *html = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"www/content/island-1" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL];
NSString *path = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:path];
[webView loadHTMLString:html baseURL:baseURL];
within the html files, here are code references to some content:
<script type="text/javascript" src="../static/js/custom-event.js"></script>
<script type="text/javascript" src="../static/js/touch-source/Browser/Features.Touch.js"></script>
<link rel="stylesheet" href="../static/css/islands_popup.css">
<link rel="stylesheet" href="../static/css/content.css">
All folders and files are correct and none are missing. Does anyone know what I might be doing wrong?
XCode doesn’t use folders, it use just its bundle to store all data. So I would advise you to use:
Instand of:
Same with your css and other files.
Also if we talk about
.jsfiles be sure to delete files from::Targets–>Build Phases—>Compile Sources
and add to
Targets–>Build Phases—>Copy Bundle Resources
Because when you first add
.jsfiles to project XCode somehow thinks it needs to be compiled.