0

I'm loading HTML-formatted content into my app from a web service, then plugging that into a local HTML template that lives within the app. Now, I need to set the UIWebView's BaseURL to point at the remote server so that all relative image links will load. However, I'm also trying to link in some local assets (CSS, JavaScript). Thus far, I have not found any documentation on how to link in local assets without relying on the UIWebView's baseURL. I've tried injecting the absolute file path of my CSS and JS into my HTML template, but it hasn't worked... I don't know if that means that it doesn't work, or if I'm just doing it wrong.

Has anyone ever run into this scenario, and if so, how did you address it? Thanks in advance, I really appreciate any tips!

1 Answer 1

0

How are you injecting the local path? My approach would be:

NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"script" ofType:@"js"];
NSURL *url = [NSURL fileURLWithPath:pathToFile];
NSString *injectString = url.absoluteString;

Although, I couldn't tell you if this actually works or not, since I have never tried it. The other option is to instead use the local path as the base URL, and inject the remote path for files instead. I'm not sure how your HTML is formatted, or what changes you'd have to make to do it that way, but that would much more likely work if this approach does not.

1
  • I tried the solution you posted here a while ago, and it appears not to work... which I find really odd. One would think that an absolute file path would be a given. However, it appears that a UIWebView BaseURL is doing something else behind the scenes to make the local include work. For the time being, I'm just embedding all include data into my main HTML template, including images as base64. It's not pretty, but it's addressing the problem.
    – bigmac
    Jun 1, 2010 at 16:03

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.