views:

48

answers:

2

I'd like to use UIWebView's - (void)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL

but I'm not sure what this baseURL is good for or how I would create that. My file is called localHTMLfile.html and I know how I would load this file the normal way:

NSURL *url = [[NSBundle mainBundle] URLForResource:@"localHTMLfile" withExtension:@"html"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webview loadRequest:request];

So it's just a raw guess, but would that baseURL be the NSURL object I've created already? Does that make sense?

A: 

baseURL would be a file: URL that points to the directory the local HTML file is stored in. It will be used to convert any relative paths in the HTML file (e.g. references to CSS or image files) to their absolute locations.

Ole Begemann
+1  A: 

The whole point of a UIWebView is to show a web page. Therefore the base URL will be the path where relative links in the HTML document will point to.

If you're showing http://mywebpage.com/this/that/foo/bar.html then your base URL will be the base URL of that page - wherever relative links and such are pointing to. Its so that any links eg <a href="../hello.html">This is a link</a> will be pointed to reliably.

For you I guess you could do: [NSURL URLWithString:[[NSBundle mainBundle] bundlePath]]

Thomas Clayson