- (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"]; }
source share