What loads the HTMLML String: baseURL:

I am new to iOS programming and tried to figure out what loadHTMLString:baseURL: really does, but I cannot find a satisfactory explanation. Apple's website just says:

Sets the main content and base URL.

Can someone explain this in more detail for me?

+6
source share
3 answers

I am pretty sure that baseURL is used in the same way as it is on regular web pages to properly load links that are referenced using relative links. Now the question is how to set this base URL to a specific folder in the application directory.

+4
source

This is how content is loaded into webView. either from a local html file, or through a URL.

 //this is to load local html file. Read the file & give the file contents to webview. [webView loadHTMLString:someHTMLstring baseURL:[NSURL URLWithString:@""]]; //if webview loads content through a url then [webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://google.com"]]] 
+3
source
 - (void) loadHTMLString:(NSString *)string baseURL:(nullable NSURL *)baseURL; 

used to load a local HTML file, the parameter string means the content of the html file, if your HTML file contains an href tag with a relative path, you must set the baseUrl parameter with the base address of the HTML file or set it to nil .

 NSString *cachePath = [self cachePath]; NSString *indexHTMLPath = [NSString stringWithFormat:@"%@/index.html", cachePath]; if ([self fileIsExsit:indexHTMLPath]) { NSString *htmlCont = [NSString stringWithContentsOfFile:indexHTMLPath encoding:NSUTF8StringEncoding error:nil]; NSURL *baseURL = [NSURL fileURLWithPath:cachePath]; [self.webView loadHTMLString:htmlCont baseURL:baseURL]; } - (NSString *)cachePath { NSArray* cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); return [cachePath[0] stringByAppendingPathComponent:@"movie"]; } 
+1
source

Source: https://habr.com/ru/post/902917/


All Articles