1

When my UIWebView loads my index.html the CSS and JavaScript references show as broken. What is wrong with the code below? (I verified that appUrlString is pointing to the correct directory)

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@""];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];

NSString *appUrlString = [NSString stringWithFormat:@"%@/web/", [[NSBundle mainBundle] resourcePath]];
NSURL *appUrl = [NSURL URLWithString:appUrlString];

[_appWebView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:appUrl];

This is what shows in the simulator.

enter image description here

1 Answer 1

3

You should use

NSURL *appUrl = [NSURL fileURLWithPath:appUrlString];

because it's a local filePath. In your version 'appURL' was giving back nil. So no baseurl got set.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.